From 73e88a037ad4f6f40867df6964b64b86a4c3a823 Mon Sep 17 00:00:00 2001 From: RadAzzouz Date: Mon, 14 Sep 2020 10:50:18 -0400 Subject: [PATCH 1/2] 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 --- ios/RCTPSPDFKit/RCTPSPDFKitView.m | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/ios/RCTPSPDFKit/RCTPSPDFKitView.m b/ios/RCTPSPDFKit/RCTPSPDFKitView.m index 3e23e788..ed3b6852 100644 --- a/ios/RCTPSPDFKit/RCTPSPDFKitView.m +++ b/ios/RCTPSPDFKit/RCTPSPDFKitView.m @@ -15,6 +15,9 @@ #define VALIDATE_DOCUMENT(document, ...) { if (!document.isValid) { NSLog(@"Document is invalid."); if (self.onDocumentLoadFailed) { self.onDocumentLoadFailed(@{@"error": @"Document is invalid."}); } return __VA_ARGS__; }} +@interface RCTPSPDFKitViewController : PSPDFViewController +@end + @interface RCTPSPDFKitView () @property (nonatomic, nullable) UIViewController *topController; @@ -25,7 +28,7 @@ @implementation RCTPSPDFKitView - (instancetype)initWithFrame:(CGRect)frame { if ((self = [super initWithFrame:frame])) { - _pdfController = [[PSPDFViewController alloc] init]; + _pdfController = [[RCTPSPDFKitViewController alloc] init]; _pdfController.delegate = self; _pdfController.annotationToolbarController.delegate = self; _closeButton = [[UIBarButtonItem alloc] initWithImage:[PSPDFKitGlobal imageNamed:@"x"] style:UIBarButtonItemStylePlain target:self action:@selector(closeButtonPressed:)]; @@ -58,9 +61,8 @@ - (void)didMoveToWindow { if (self.pdfController.configuration.useParentNavigationBar || self.hideNavigationBar) { self.topController = self.pdfController; - } else { - self.topController = [[PSPDFNavigationController alloc] initWithRootViewController:self.pdfController];; + self.topController = [[PSPDFNavigationController alloc] initWithRootViewController:self.pdfController]; } UIView *topControllerView = self.topController.view; @@ -477,3 +479,25 @@ - (void)onStateChangedForPDFViewController:(PSPDFViewController *)pdfController } @end + +@implementation RCTPSPDFKitViewController + +- (void)viewWillTransitionToSize:(CGSize)newSize withTransitionCoordinator:(id)coordinator { + [super viewWillTransitionToSize:newSize withTransitionCoordinator:coordinator]; + + /* Workaround for internal issue 25653: + We re-apply the current view state to workaround an issue where the last page view would be layed out incorrectly + in single page mode and scroll per spread page trasition after device rotation. + + We do this because the `PSPDFViewController` is not embedded as recommended in + https://pspdfkit.com/guides/ios/current/customizing-the-interface/embedding-the-pdfviewcontroller-inside-a-custom-container-view-controller + and because React Native itself handles the React Native view. + + TL;DR: We are adding the `PSPDFViewController` to `RCTPSPDFKitView` and not to the container controller's view. + */ + [coordinator animateAlongsideTransition:NULL completion:^(id context) { + [self applyViewState:self.viewState animateIfPossible:NO]; + }]; +} + +@end From 2ed586140e26c5db19290be480ebbfa60a931c6e Mon Sep 17 00:00:00 2001 From: RadAzzouz Date: Mon, 14 Sep 2020 12:21:29 -0400 Subject: [PATCH 2/2] Bump version to 1.29.10 --- package-lock.json | 2 +- package.json | 2 +- samples/Catalog/package.json | 2 +- samples/NativeCatalog/package.json | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/package-lock.json b/package-lock.json index 38699fd9..f4fc9370 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "react-native-pspdfkit", - "version": "1.29.9", + "version": "1.29.10", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 8d1aec29..e7a644b4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-native-pspdfkit", - "version": "1.29.9", + "version": "1.29.10", "description": "A React Native module for the PSPDFKit library.", "keywords": [ "react native", diff --git a/samples/Catalog/package.json b/samples/Catalog/package.json index 25583261..b9861c64 100644 --- a/samples/Catalog/package.json +++ b/samples/Catalog/package.json @@ -1,6 +1,6 @@ { "name": "Catalog", - "version": "1.29.9", + "version": "1.29.10", "private": true, "scripts": { "start": "react-native start", diff --git a/samples/NativeCatalog/package.json b/samples/NativeCatalog/package.json index 52b93750..8b214783 100644 --- a/samples/NativeCatalog/package.json +++ b/samples/NativeCatalog/package.json @@ -1,6 +1,6 @@ { "name": "NativeCatalog", - "version": "1.29.9", + "version": "1.29.10", "private": true, "scripts": { "android": "react-native run-android",