Skip to content

Commit 25d5bc6

Browse files
authored
Merge pull request #377 from PSPDFKit/rad/fix-last-page-view-layout-after-rotation
Fixes issue where the last page view would be layed out incorrectly in single page mode and scroll per spread page trasition after device rotation
2 parents 354738e + 2ed5861 commit 25d5bc6

File tree

5 files changed

+31
-7
lines changed

5 files changed

+31
-7
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

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-pspdfkit",
3-
"version": "1.29.9",
3+
"version": "1.29.10",
44
"description": "A React Native module for the PSPDFKit library.",
55
"keywords": [
66
"react native",

samples/Catalog/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "Catalog",
3-
"version": "1.29.9",
3+
"version": "1.29.10",
44
"private": true,
55
"scripts": {
66
"start": "react-native start",

samples/NativeCatalog/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "NativeCatalog",
3-
"version": "1.29.9",
3+
"version": "1.29.10",
44
"private": true,
55
"scripts": {
66
"android": "react-native run-android",

0 commit comments

Comments
 (0)