Skip to content

Commit 89104ea

Browse files
authored
Merge pull request #81 from PSPDFKit/rad/js-events-ios
Add onDocumentSaved event for the UI Component
2 parents f726942 + 2a6e5b6 commit 89104ea

File tree

4 files changed

+32
-3
lines changed

4 files changed

+32
-3
lines changed

index.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ class PSPDFKitView extends React.Component {
2929
{...this.props}
3030
onCloseButtonPressed={onCloseButtonPressedHandler}
3131
onStateChanged={this._onStateChanged}
32+
onDocumentSaved={this._onDocumentSaved}
3233
/>
3334
);
3435
} else {
@@ -41,6 +42,12 @@ class PSPDFKitView extends React.Component {
4142
this.props.onStateChanged(event.nativeEvent);
4243
}
4344
};
45+
46+
_onDocumentSaved = (event) => {
47+
if (this.props.onDocumentSaved) {
48+
this.props.onDocumentSaved(event.nativeEvent);
49+
}
50+
};
4451

4552
/**
4653
* Enters the annotation creation mode, showing the annotation creation toolbar.
@@ -108,6 +115,12 @@ PSPDFKitView.propTypes = {
108115
* @platform ios
109116
*/
110117
onCloseButtonPressed: PropTypes.func,
118+
/**
119+
* Callback that is called when the document is saved.
120+
*
121+
* @platform ios
122+
*/
123+
onDocumentSaved: PropTypes.func,
111124
/**
112125
* Callback that is called when the state of the PSPDFKitView changes.
113126
* Returns an object with the following structure:

ios/RCTPSPDFKit/RCTPSPDFKitView.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717

1818
@property (nonatomic, readonly) PSPDFViewController *pdfController;
1919
@property (nonatomic) BOOL hideNavigationBar;
20-
2120
@property (nonatomic, readonly) UIBarButtonItem *closeButton;
2221
@property (nonatomic, copy) RCTBubblingEventBlock onCloseButtonPressed;
22+
@property (nonatomic, copy) RCTBubblingEventBlock onDocumentSaved;
2323

2424
@end

ios/RCTPSPDFKit/RCTPSPDFKitView.m

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#import "RCTPSPDFKitView.h"
1111
#import <React/RCTUtils.h>
1212

13-
@interface RCTPSPDFKitView ()
13+
@interface RCTPSPDFKitView ()<PSPDFDocumentDelegate>
1414

1515
@property (nonatomic, nullable) UIViewController *topController;
1616

@@ -97,4 +97,12 @@ - (UIViewController *)pspdf_parentViewController {
9797
return nil;
9898
}
9999

100+
#pragma mark - PSPDFDocumentDelegate
101+
102+
- (void)pdfDocumentDidSave:(nonnull PSPDFDocument *)document {
103+
if (self.onDocumentSaved) {
104+
self.onDocumentSaved(@{});
105+
}
106+
}
107+
100108
@end

ios/RCTPSPDFKit/RCTPSPDFKitViewManager.m

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
#import "RCTPSPDFKitViewManager.h"
1111
#import "RCTConvert+PSPDFConfiguration.h"
12+
#import "RCTConvert+PSPDFDocument.h"
1213
#import "RCTPSPDFKitView.h"
1314

1415
@import PSPDFKit;
@@ -18,7 +19,12 @@ @implementation RCTPSPDFKitViewManager
1819

1920
RCT_EXPORT_MODULE()
2021

21-
RCT_REMAP_VIEW_PROPERTY(document, pdfController.document, PSPDFDocument)
22+
RCT_CUSTOM_VIEW_PROPERTY(document, pdfController.document, RCTPSPDFKitView) {
23+
if (json) {
24+
view.pdfController.document = [RCTConvert PSPDFDocument:json];
25+
view.pdfController.document.delegate = (id<PSPDFDocumentDelegate>)view;
26+
}
27+
}
2228

2329
RCT_REMAP_VIEW_PROPERTY(pageIndex, pdfController.pageIndex, NSUInteger)
2430

@@ -42,6 +48,8 @@ @implementation RCTPSPDFKitViewManager
4248

4349
RCT_EXPORT_VIEW_PROPERTY(onCloseButtonPressed, RCTBubblingEventBlock)
4450

51+
RCT_EXPORT_VIEW_PROPERTY(onDocumentSaved, RCTBubblingEventBlock)
52+
4553
- (UIView *)view {
4654
return [[RCTPSPDFKitView alloc] init];
4755
}

0 commit comments

Comments
 (0)