15
15
16
16
#define VALIDATE_DOCUMENT (document, ...) { if (!document.isValid ) { NSLog (@" Document is invalid." ); if (self.onDocumentLoadFailed ) { self.onDocumentLoadFailed (@{@" error" : @" Document is invalid." }); } return __VA_ARGS__; }}
17
17
18
+ @interface RCTPSPDFKitViewController : PSPDFViewController
19
+ @end
20
+
18
21
@interface RCTPSPDFKitView ()<PSPDFDocumentDelegate, PSPDFViewControllerDelegate, PSPDFFlexibleToolbarContainerDelegate>
19
22
20
23
@property (nonatomic , nullable ) UIViewController *topController;
@@ -25,7 +28,7 @@ @implementation RCTPSPDFKitView
25
28
26
29
- (instancetype )initWithFrame : (CGRect)frame {
27
30
if ((self = [super initWithFrame: frame])) {
28
- _pdfController = [[PSPDFViewController alloc ] init ];
31
+ _pdfController = [[RCTPSPDFKitViewController alloc ] init ];
29
32
_pdfController.delegate = self;
30
33
_pdfController.annotationToolbarController .delegate = self;
31
34
_closeButton = [[UIBarButtonItem alloc ] initWithImage: [PSPDFKitGlobal imageNamed: @" x" ] style: UIBarButtonItemStylePlain target: self action: @selector (closeButtonPressed: )];
@@ -58,9 +61,8 @@ - (void)didMoveToWindow {
58
61
59
62
if (self.pdfController .configuration .useParentNavigationBar || self.hideNavigationBar ) {
60
63
self.topController = self.pdfController ;
61
-
62
64
} else {
63
- self.topController = [[PSPDFNavigationController alloc ] initWithRootViewController: self .pdfController];;
65
+ self.topController = [[PSPDFNavigationController alloc ] initWithRootViewController: self .pdfController];
64
66
}
65
67
66
68
UIView *topControllerView = self.topController .view ;
@@ -477,3 +479,25 @@ - (void)onStateChangedForPDFViewController:(PSPDFViewController *)pdfController
477
479
}
478
480
479
481
@end
482
+
483
+ @implementation RCTPSPDFKitViewController
484
+
485
+ - (void )viewWillTransitionToSize : (CGSize)newSize withTransitionCoordinator : (id <UIViewControllerTransitionCoordinator>)coordinator {
486
+ [super viewWillTransitionToSize: newSize withTransitionCoordinator: coordinator];
487
+
488
+ /* Workaround for internal issue 25653:
489
+ We re-apply the current view state to workaround an issue where the last page view would be layed out incorrectly
490
+ in single page mode and scroll per spread page trasition after device rotation.
491
+
492
+ We do this because the `PSPDFViewController` is not embedded as recommended in
493
+ https://pspdfkit.com/guides/ios/current/customizing-the-interface/embedding-the-pdfviewcontroller-inside-a-custom-container-view-controller
494
+ and because React Native itself handles the React Native view.
495
+
496
+ TL;DR: We are adding the `PSPDFViewController` to `RCTPSPDFKitView` and not to the container controller's view.
497
+ */
498
+ [coordinator animateAlongsideTransition: NULL completion: ^(id <UIViewControllerTransitionCoordinatorContext> context) {
499
+ [self applyViewState: self .viewState animateIfPossible: NO ];
500
+ }];
501
+ }
502
+
503
+ @end
0 commit comments