Skip to content

Commit 2415344

Browse files
author
RadAzzouz
committed
Add onDocumentSaved event for the UI Component
1 parent f726942 commit 2415344

File tree

4 files changed

+37
-2
lines changed

4 files changed

+37
-2
lines changed

index.js

Lines changed: 15 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,14 @@ PSPDFKitView.propTypes = {
108115
* @platform ios
109116
*/
110117
onCloseButtonPressed: PropTypes.func,
118+
119+
/**
120+
* Callback that is called when the document is saved.
121+
*
122+
* @platform ios
123+
*/
124+
onDocumentSaved: PropTypes.func,
125+
111126
/**
112127
* Callback that is called when the state of the PSPDFKitView changes.
113128
* Returns an object with the following structure:

ios/RCTPSPDFKit/RCTPSPDFKitView.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,6 @@
2020

2121
@property (nonatomic, readonly) UIBarButtonItem *closeButton;
2222
@property (nonatomic, copy) RCTBubblingEventBlock onCloseButtonPressed;
23+
@property (nonatomic, copy) RCTBubblingEventBlock onDocumentSaved;
2324

2425
@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: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,25 @@
99

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

1415
@import PSPDFKit;
1516
@import PSPDFKitUI;
1617

18+
@interface RCTPSPDFKitViewManager() <PSPDFDocumentDelegate>
19+
@end
20+
1721
@implementation RCTPSPDFKitViewManager
1822

1923
RCT_EXPORT_MODULE()
2024

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

2332
RCT_REMAP_VIEW_PROPERTY(pageIndex, pdfController.pageIndex, NSUInteger)
2433

@@ -42,6 +51,8 @@ @implementation RCTPSPDFKitViewManager
4251

4352
RCT_EXPORT_VIEW_PROPERTY(onCloseButtonPressed, RCTBubblingEventBlock)
4453

54+
RCT_EXPORT_VIEW_PROPERTY(onDocumentSaved, RCTBubblingEventBlock)
55+
4556
- (UIView *)view {
4657
return [[RCTPSPDFKitView alloc] init];
4758
}

0 commit comments

Comments
 (0)