@@ -557,7 +557,7 @@ extension FileDetailsViewController: QLPreviewControllerDataSource, QLPreviewCon
557
557
}
558
558
}
559
559
560
- extension FileDetailsViewController : PDFViewControllerDelegate {
560
+ extension FileDetailsViewController : PDFViewControllerDelegate , FlexibleToolbarContainerDelegate {
561
561
func embedPDFView( for url: URL ) {
562
562
guard DocViewerViewController . hasPSPDFKitLicense else {
563
563
return embedWebView ( for: url)
@@ -581,7 +581,8 @@ extension FileDetailsViewController: PDFViewControllerDelegate {
581
581
// Override the override
582
582
builder. overrideClass ( AnnotationToolbar . self, with: AnnotationToolbar . self)
583
583
} )
584
- controller. annotationToolbarController? . toolbar. toolbarPosition = . left
584
+ controller. annotationToolbarController? . annotationToolbar. toolbarPosition = defaultToolbarPosition ( )
585
+ controller. annotationToolbarController? . delegate = self
585
586
586
587
let appearance = UIToolbarAppearance ( )
587
588
appearance. configureWithOpaqueBackground ( )
@@ -610,6 +611,29 @@ extension FileDetailsViewController: PDFViewControllerDelegate {
610
611
doneLoading ( )
611
612
}
612
613
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
+
613
637
func saveAnnotations( ) {
614
638
for child in children {
615
639
if let pdf = child as? PDFViewController {
0 commit comments