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
22 changes: 20 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class PSPDFKitView extends React.Component {
onCloseButtonPressed={onCloseButtonPressedHandler}
onStateChanged={this._onStateChanged}
onDocumentSaved={this._onDocumentSaved}
onAnnotationTapped={this._onAnnotationTapped}
/>
);
} else {
Expand All @@ -48,6 +49,12 @@ class PSPDFKitView extends React.Component {
this.props.onDocumentSaved(event.nativeEvent);
}
};

_onAnnotationTapped = (event) => {
if (this.props.onAnnotationTapped) {
this.props.onAnnotationTapped(event.nativeEvent);
}
};

/**
* Enters the annotation creation mode, showing the annotation creation toolbar.
Expand Down Expand Up @@ -107,6 +114,12 @@ PSPDFKitView.propTypes = {
* @platform ios
*/
showCloseButton: PropTypes.bool,
/**
* Controls wheter or not the default action for tapped annotations is processed. Defaults to processing the action (false).
*
* @platform ios
*/
disableDefaultActionForTappedAnnotations: PropTypes.bool,
/**
* Callback that is called when the user tapped the close button.
* If you provide this function, you need to handle dismissal yourself.
Expand All @@ -120,7 +133,13 @@ PSPDFKitView.propTypes = {
*
* @platform ios
*/
onDocumentSaved: PropTypes.func,
onDocumentSaved: PropTypes.func,
/**
* Callback that is called when the user taps on an annotation.
*
* @platform ios
*/
onAnnotationTapped: PropTypes.func,
/**
* Callback that is called when the state of the PSPDFKitView changes.
* Returns an object with the following structure:
Expand All @@ -137,7 +156,6 @@ PSPDFKitView.propTypes = {
* @platform android
*/
onStateChanged: PropTypes.func,

/**
* fragmentTag: A tag used to identify a single PdfFragment in the view hierarchy.
* This needs to be unique in the view hierarchy.
Expand Down
2 changes: 2 additions & 0 deletions ios/RCTPSPDFKit/RCTPSPDFKitView.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
@property (nonatomic, readonly) PSPDFViewController *pdfController;
@property (nonatomic) BOOL hideNavigationBar;
@property (nonatomic, readonly) UIBarButtonItem *closeButton;
@property (nonatomic) BOOL disableDefaultActionForTappedAnnotations;
@property (nonatomic, copy) RCTBubblingEventBlock onCloseButtonPressed;
@property (nonatomic, copy) RCTBubblingEventBlock onDocumentSaved;
@property (nonatomic, copy) RCTBubblingEventBlock onAnnotationTapped;

@end
14 changes: 13 additions & 1 deletion ios/RCTPSPDFKit/RCTPSPDFKitView.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#import "RCTPSPDFKitView.h"
#import <React/RCTUtils.h>

@interface RCTPSPDFKitView ()<PSPDFDocumentDelegate>
@interface RCTPSPDFKitView ()<PSPDFDocumentDelegate, PSPDFViewControllerDelegate>

@property (nonatomic, nullable) UIViewController *topController;

Expand All @@ -21,6 +21,7 @@ @implementation RCTPSPDFKitView
- (instancetype)initWithFrame:(CGRect)frame {
if ((self = [super initWithFrame:frame])) {
_pdfController = [[PSPDFViewController alloc] init];
_pdfController.delegate = self;
_closeButton = [[UIBarButtonItem alloc] initWithImage:[PSPDFKit imageNamed:@"x"] style:UIBarButtonItemStylePlain target:self action:@selector(closeButtonPressed:)];
}

Expand Down Expand Up @@ -105,4 +106,15 @@ - (void)pdfDocumentDidSave:(nonnull PSPDFDocument *)document {
}
}

#pragma mark - PSPDFViewControllerDelegate

- (BOOL)pdfViewController:(PSPDFViewController *)pdfController didTapOnAnnotation:(PSPDFAnnotation *)annotation annotationPoint:(CGPoint)annotationPoint annotationView:(UIView<PSPDFAnnotationPresenting> *)annotationView pageView:(PSPDFPageView *)pageView viewPoint:(CGPoint)viewPoint {
if (self.onAnnotationTapped) {
NSData *annotationData = [annotation generateInstantJSONWithError:NULL];
NSDictionary *annotationDictionary = [NSJSONSerialization JSONObjectWithData:annotationData options:kNilOptions error:NULL];
self.onAnnotationTapped(annotationDictionary);
}
return self.disableDefaultActionForTappedAnnotations;
}

@end
4 changes: 4 additions & 0 deletions ios/RCTPSPDFKit/RCTPSPDFKitViewManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ @implementation RCTPSPDFKitViewManager

RCT_EXPORT_VIEW_PROPERTY(hideNavigationBar, BOOL)

RCT_EXPORT_VIEW_PROPERTY(disableDefaultActionForTappedAnnotations, BOOL)

RCT_REMAP_VIEW_PROPERTY(color, tintColor, UIColor)

RCT_CUSTOM_VIEW_PROPERTY(showCloseButton, BOOL, RCTPSPDFKitView) {
Expand All @@ -50,6 +52,8 @@ @implementation RCTPSPDFKitViewManager

RCT_EXPORT_VIEW_PROPERTY(onDocumentSaved, RCTBubblingEventBlock)

RCT_EXPORT_VIEW_PROPERTY(onAnnotationTapped, RCTBubblingEventBlock)

- (UIView *)view {
return [[RCTPSPDFKitView alloc] init];
}
Expand Down