Skip to content

Commit 4548dd4

Browse files
Fix the issue of annotation bar move button being cut off on landscape mode (#2957)
refs: MBL-17988 affects: Student,Teacher release note: Fix the issue of annotation bar move button being cut off on landscape mode. test plan: See PR description
1 parent 66815c5 commit 4548dd4

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

Core/Core/Files/View/FileDetails/FileDetailsViewController.swift

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,7 @@ extension FileDetailsViewController: QLPreviewControllerDataSource, QLPreviewCon
557557
}
558558
}
559559

560-
extension FileDetailsViewController: PDFViewControllerDelegate {
560+
extension FileDetailsViewController: PDFViewControllerDelegate, FlexibleToolbarContainerDelegate {
561561
func embedPDFView(for url: URL) {
562562
guard DocViewerViewController.hasPSPDFKitLicense else {
563563
return embedWebView(for: url)
@@ -581,7 +581,8 @@ extension FileDetailsViewController: PDFViewControllerDelegate {
581581
// Override the override
582582
builder.overrideClass(AnnotationToolbar.self, with: AnnotationToolbar.self)
583583
})
584-
controller.annotationToolbarController?.toolbar.toolbarPosition = .left
584+
controller.annotationToolbarController?.annotationToolbar.toolbarPosition = defaultToolbarPosition()
585+
controller.annotationToolbarController?.delegate = self
585586

586587
let appearance = UIToolbarAppearance()
587588
appearance.configureWithOpaqueBackground()
@@ -610,6 +611,29 @@ extension FileDetailsViewController: PDFViewControllerDelegate {
610611
doneLoading()
611612
}
612613

614+
private func defaultToolbarPosition() -> FlexibleToolbar.Position {
615+
let isRegular = view.traitCollection.horizontalSizeClass == .regular
616+
let isRightToLeft = view.traitCollection.layoutDirection == .rightToLeft
617+
return !isRegular || isRightToLeft ? .left : .right
618+
}
619+
620+
public func flexibleToolbarContainerContentRect(_ container: FlexibleToolbarContainer, for position: FlexibleToolbar.Position) -> CGRect {
621+
622+
let isCompact = container.traitCollection.horizontalSizeClass == .compact
623+
let padding: CGFloat = isCompact ? 10 : 16
624+
625+
let safeInsets = container.safeAreaInsets
626+
let contentFrame = contentView.convert(contentView.bounds, to: container)
627+
let toolbarRect = CGRect(
628+
x: safeInsets.left + padding,
629+
y: contentFrame.origin.y,
630+
width: container.bounds.width - safeInsets.left - safeInsets.right - 2 * padding,
631+
height: contentFrame.height
632+
)
633+
634+
return toolbarRect
635+
}
636+
613637
func saveAnnotations() {
614638
for child in children {
615639
if let pdf = child as? PDFViewController {

0 commit comments

Comments
 (0)