Skip to content

Commit 73e88a0

Browse files
author
RadAzzouz
committed
Fix issue where the last page view would be layed out incorrectly in single page mode and scroll per spread page trasition after device rotation
1 parent 354738e commit 73e88a0

File tree

1 file changed

+27
-3
lines changed

1 file changed

+27
-3
lines changed

ios/RCTPSPDFKit/RCTPSPDFKitView.m

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515

1616
#define VALIDATE_DOCUMENT(document, ...) { if (!document.isValid) { NSLog(@"Document is invalid."); if (self.onDocumentLoadFailed) { self.onDocumentLoadFailed(@{@"error": @"Document is invalid."}); } return __VA_ARGS__; }}
1717

18+
@interface RCTPSPDFKitViewController : PSPDFViewController
19+
@end
20+
1821
@interface RCTPSPDFKitView ()<PSPDFDocumentDelegate, PSPDFViewControllerDelegate, PSPDFFlexibleToolbarContainerDelegate>
1922

2023
@property (nonatomic, nullable) UIViewController *topController;
@@ -25,7 +28,7 @@ @implementation RCTPSPDFKitView
2528

2629
- (instancetype)initWithFrame:(CGRect)frame {
2730
if ((self = [super initWithFrame:frame])) {
28-
_pdfController = [[PSPDFViewController alloc] init];
31+
_pdfController = [[RCTPSPDFKitViewController alloc] init];
2932
_pdfController.delegate = self;
3033
_pdfController.annotationToolbarController.delegate = self;
3134
_closeButton = [[UIBarButtonItem alloc] initWithImage:[PSPDFKitGlobal imageNamed:@"x"] style:UIBarButtonItemStylePlain target:self action:@selector(closeButtonPressed:)];
@@ -58,9 +61,8 @@ - (void)didMoveToWindow {
5861

5962
if (self.pdfController.configuration.useParentNavigationBar || self.hideNavigationBar) {
6063
self.topController = self.pdfController;
61-
6264
} else {
63-
self.topController = [[PSPDFNavigationController alloc] initWithRootViewController:self.pdfController];;
65+
self.topController = [[PSPDFNavigationController alloc] initWithRootViewController:self.pdfController];
6466
}
6567

6668
UIView *topControllerView = self.topController.view;
@@ -477,3 +479,25 @@ - (void)onStateChangedForPDFViewController:(PSPDFViewController *)pdfController
477479
}
478480

479481
@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

Comments
 (0)