Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 27 additions & 3 deletions ios/RCTPSPDFKit/RCTPSPDFKitView.m
Original file line number Diff line number Diff line change
Expand Up @@ -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 ()<PSPDFDocumentDelegate, PSPDFViewControllerDelegate, PSPDFFlexibleToolbarContainerDelegate>

@property (nonatomic, nullable) UIViewController *topController;
Expand All @@ -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:)];
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -477,3 +479,25 @@ - (void)onStateChangedForPDFViewController:(PSPDFViewController *)pdfController
}

@end

@implementation RCTPSPDFKitViewController

- (void)viewWillTransitionToSize:(CGSize)newSize withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)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<UIViewControllerTransitionCoordinatorContext> context) {
[self applyViewState:self.viewState animateIfPossible:NO];
}];
}

@end
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion samples/Catalog/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Catalog",
"version": "1.29.9",
"version": "1.29.10",
"private": true,
"scripts": {
"start": "react-native start",
Expand Down
2 changes: 1 addition & 1 deletion samples/NativeCatalog/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "NativeCatalog",
"version": "1.29.9",
"version": "1.29.10",
"private": true,
"scripts": {
"android": "react-native run-android",
Expand Down