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
122 changes: 106 additions & 16 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ class PSPDFKitView extends React.Component {
if (Platform.OS === "ios" || Platform.OS === "android") {
const onCloseButtonPressedHandler = this.props.onCloseButtonPressed
? event => {
this.props.onCloseButtonPressed(event.nativeEvent);
}
this.props.onCloseButtonPressed(event.nativeEvent);
}
: null;
return (
<RCTPSPDFKitView
Expand Down Expand Up @@ -89,7 +89,7 @@ class PSPDFKitView extends React.Component {
/**
* Enters the annotation creation mode, showing the annotation creation toolbar.
*/
enterAnnotationCreationMode = function () {
enterAnnotationCreationMode = function() {
if (Platform.OS === "android") {
UIManager.dispatchViewManagerCommand(
findNodeHandle(this.refs.pdfView),
Expand All @@ -106,7 +106,7 @@ class PSPDFKitView extends React.Component {
/**
* Exits the currently active mode, hiding all toolbars.
*/
exitCurrentlyActiveMode = function () {
exitCurrentlyActiveMode = function() {
if (Platform.OS === "android") {
UIManager.dispatchViewManagerCommand(
findNodeHandle(this.refs.pdfView),
Expand All @@ -123,7 +123,7 @@ class PSPDFKitView extends React.Component {
/**
* Saves the currently opened document.
*/
saveCurrentDocument = function () {
saveCurrentDocument = function() {
if (Platform.OS === "android") {
UIManager.dispatchViewManagerCommand(
findNodeHandle(this.refs.pdfView),
Expand All @@ -146,13 +146,13 @@ class PSPDFKitView extends React.Component {
* Returns a promise resolving an array with the following structure:
* {'annotations' : [instantJson]}
*/
getAnnotations = function (pageIndex, type) {
getAnnotations = function(pageIndex, type) {
if (Platform.OS === "android") {
let requestId = this._nextRequestId++;
let requestMap = this._requestMap;

// We create a promise here that will be resolved once onDataReturned is called.
let promise = new Promise(function (resolve, reject) {
let promise = new Promise(function(resolve, reject) {
requestMap[requestId] = { resolve: resolve, reject: reject };
});

Expand All @@ -177,7 +177,7 @@ class PSPDFKitView extends React.Component {
*
* @param annotation InstantJson of the annotation to add.
*/
addAnnotation = function (annotation) {
addAnnotation = function(annotation) {
if (Platform.OS === "android") {
UIManager.dispatchViewManagerCommand(
findNodeHandle(this.refs.pdfView),
Expand All @@ -197,7 +197,7 @@ class PSPDFKitView extends React.Component {
*
* @param annotation InstantJson of the annotation to remove.
*/
removeAnnotation = function (annotation) {
removeAnnotation = function(annotation) {
if (Platform.OS === "android") {
UIManager.dispatchViewManagerCommand(
findNodeHandle(this.refs.pdfView),
Expand All @@ -217,13 +217,13 @@ class PSPDFKitView extends React.Component {
*
* Returns a promise resolving to document instant json (https://pspdfkit.com/guides/android/current/importing-exporting/instant-json/#instant-document-json-api-a56628).
*/
getAllUnsavedAnnotations = function () {
getAllUnsavedAnnotations = function() {
if (Platform.OS === "android") {
let requestId = this._nextRequestId++;
let requestMap = this._requestMap;

// We create a promise here that will be resolved once onDataReturned is called.
let promise = new Promise(function (resolve, reject) {
let promise = new Promise(function(resolve, reject) {
requestMap[requestId] = { resolve: resolve, reject: reject };
});

Expand All @@ -246,7 +246,7 @@ class PSPDFKitView extends React.Component {
*
* @param annotations The document instant json to apply.
*/
addAnnotations = function (annotations) {
addAnnotations = function(annotations) {
if (Platform.OS === "android") {
UIManager.dispatchViewManagerCommand(
findNodeHandle(this.refs.pdfView),
Expand All @@ -269,13 +269,13 @@ class PSPDFKitView extends React.Component {
* Returns a promise resolving a dictionary with the following structure:
* {'formElement' : value} or {'error' : 'Failed to get the form field value.'}
*/
getFormFieldValue = function (fullyQualifiedName) {
getFormFieldValue = function(fullyQualifiedName) {
if (Platform.OS === "android") {
let requestId = this._nextRequestId++;
let requestMap = this._requestMap;

// We create a promise here that will be resolved once onDataReturned is called.
let promise = new Promise(function (resolve, reject) {
let promise = new Promise(function(resolve, reject) {
requestMap[requestId] = { resolve: resolve, reject: reject };
});

Expand All @@ -300,7 +300,7 @@ class PSPDFKitView extends React.Component {
* @param fullyQualifiedName The fully qualified name of the form element.
* @param value The string value form element. For button form elements pass 'selected' or 'deselected'. For choice form elements, pass the index of the choice to select, for example '1'.
*/
setFormFieldValue = function (fullyQualifiedName, value) {
setFormFieldValue = function(fullyQualifiedName, value) {
if (Platform.OS === "android") {
UIManager.dispatchViewManagerCommand(
findNodeHandle(this.refs.pdfView),
Expand All @@ -315,6 +315,80 @@ class PSPDFKitView extends React.Component {
);
}
};
/**
* Set the left bar button items for the specified view mode.
* Note: The same button item cannot be added to both the left and right bar button items simultaneously.
*
* @param items The list of bar button items. See the full list of button items here: https://pspdfkit.com/api/ios/Classes/PSPDFViewController.html#/Toolbar%20button%20items
* @param viewMode The optional view mode. Can be 'document', 'thumbnails', 'documentEditor' or `null`. If `null` is passed, bar button items for all view modes are set.
* @param animated The animated flag.
*
* @platform ios
*/
setLeftBarButtonItems = function(items, viewMode, animated) {
if (Platform.OS === "ios") {
NativeModules.PSPDFKitViewManager.setLeftBarButtonItems(
items,
viewMode,
animated,
findNodeHandle(this.refs.pdfView)
);
}
};
/**
* Get the left bar button items for the specified view mode.
*
* @param viewMode The optional view mode. Can be 'document', 'thumbnails', 'documentEditor' or `null`. If `null` is passed, bar button items for the current view mode are returned.
*
* Returns a promise resolving an array with the following structure:
* ['outlineButtonItem', 'searchButtonItem'] or a dictionary with the following error {'error' : 'Failed to get the left bar button items.'}
* @platform ios
*/
getLeftBarButtonItemsForViewMode = function(viewMode) {
if (Platform.OS === "ios") {
return NativeModules.PSPDFKitViewManager.getLeftBarButtonItemsForViewMode(
viewMode,
findNodeHandle(this.refs.pdfView)
);
}
};
/**
* Set the right bar button items for the specified view mode.
* Note: The same button item cannot be added to both the left and right bar button items simultaneously.
*
* @param items The list of bar button items. See the full list of button items here: https://pspdfkit.com/api/ios/Classes/PSPDFViewController.html#/Toolbar%20button%20items
* @param viewMode The optional view mode. Can be 'document', 'thumbnails', 'documentEditor' or `null`. If `null` is passed, bar button items for all view modes are set.
* @param animated The animated flag.
*
* @platform ios
*/
setRightBarButtonItems = function(items, viewMode, animated) {
if (Platform.OS === "ios") {
NativeModules.PSPDFKitViewManager.setRightBarButtonItems(
items,
viewMode,
animated,
findNodeHandle(this.refs.pdfView)
);
}
};
/**
* Get the right bar button items for the specified view mode.
*
* @param viewMode The optional view mode. Can be 'document', 'thumbnails', 'documentEditor' or `null`. If `null` is passed, bar button items for the current view mode are returned.
*
* Returns a promise resolving an array with the following structure:
* ['annotationButtonItem', 'documentEditorButtonItem'] or a dictionary with the following error {'error' : 'Failed to get the right bar button items.'}
* @platform ios
*/
getRightBarButtonItemsForViewMode = function(viewMode) {
if (Platform.OS === "ios") {
return NativeModules.PSPDFKitViewManager.getRightBarButtonItemsForViewMode(
viewMode,
findNodeHandle(this.refs.pdfView)
);
}
};
}

PSPDFKitView.propTypes = {
Expand Down Expand Up @@ -425,7 +499,23 @@ PSPDFKitView.propTypes = {
/**
* menuItemGrouping: Can be used to specfiy a custom grouping for the menu items in the annotation creation toolbar.
*/
menuItemGrouping: PropTypes.array
menuItemGrouping: PropTypes.array,
/**
* leftBarButtonItems: Can be used to specfiy an array of the left button items.
* Note: The same button item cannot be added to both the left and right bar button items simultaneously.
* The full list of button items: https://pspdfkit.com/api/ios/Classes/PSPDFViewController.html#/Toolbar%20button%20items
*
* @platform ios
*/
leftBarButtonItems: PropTypes.array,
/**
* rightBarButtonItems: Can be used to specfiy an array of the right button items.
* Note: The same button item cannot be added to both the left and right bar button items simultaneously.
* The full list of button items: https://pspdfkit.com/api/ios/Classes/PSPDFViewController.html#/Toolbar%20button%20items
*
* @platform ios
*/
rightBarButtonItems: PropTypes.array
};

if (Platform.OS === "ios" || Platform.OS === "android") {
Expand Down
12 changes: 12 additions & 0 deletions ios/RCTPSPDFKit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
6572780C1D86AE7300A5E1A8 /* RCTConvert+PSPDFConfiguration.m in Sources */ = {isa = PBXBuildFile; fileRef = 657278071D86AE7300A5E1A8 /* RCTConvert+PSPDFConfiguration.m */; };
657278111D86AEC600A5E1A8 /* RCTConvert+PSPDFDocument.m in Sources */ = {isa = PBXBuildFile; fileRef = 657278101D86AEC600A5E1A8 /* RCTConvert+PSPDFDocument.m */; };
84545BA4210A5CCF00FBB0A7 /* RCTConvert+PSPDFAnnotation.m in Sources */ = {isa = PBXBuildFile; fileRef = 84545BA2210A5CCF00FBB0A7 /* RCTConvert+PSPDFAnnotation.m */; };
84694AA822AFC7510077FD01 /* RCTConvert+UIBarButtonItem.m in Sources */ = {isa = PBXBuildFile; fileRef = 84694AA722AFC7510077FD01 /* RCTConvert+UIBarButtonItem.m */; };
84BC2EAD229EE9FF00A386C6 /* RCTConvert+PSPDFViewMode.m in Sources */ = {isa = PBXBuildFile; fileRef = 84BC2EAC229EE9FF00A386C6 /* RCTConvert+PSPDFViewMode.m */; };
B783BA3421C3F55300FD981A /* RCTConvert+PSPDFAnnotationToolbarConfiguration.m in Sources */ = {isa = PBXBuildFile; fileRef = B783BA3321C3F55300FD981A /* RCTConvert+PSPDFAnnotationToolbarConfiguration.m */; };
F84F8B192032D54F00153D9E /* RCTPSPDFKitView.m in Sources */ = {isa = PBXBuildFile; fileRef = F84F8B182032D54F00153D9E /* RCTPSPDFKitView.m */; };
F8C1A2E5202DCC9700E98192 /* RCTPSPDFKitViewManager.m in Sources */ = {isa = PBXBuildFile; fileRef = F8C1A2E4202DCC9700E98192 /* RCTPSPDFKitViewManager.m */; };
Expand Down Expand Up @@ -38,6 +40,10 @@
657278101D86AEC600A5E1A8 /* RCTConvert+PSPDFDocument.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "RCTConvert+PSPDFDocument.m"; sourceTree = "<group>"; };
84545BA2210A5CCF00FBB0A7 /* RCTConvert+PSPDFAnnotation.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "RCTConvert+PSPDFAnnotation.m"; sourceTree = "<group>"; };
84545BA3210A5CCF00FBB0A7 /* RCTConvert+PSPDFAnnotation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "RCTConvert+PSPDFAnnotation.h"; sourceTree = "<group>"; };
84694AA622AFC7510077FD01 /* RCTConvert+UIBarButtonItem.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "RCTConvert+UIBarButtonItem.h"; sourceTree = "<group>"; };
84694AA722AFC7510077FD01 /* RCTConvert+UIBarButtonItem.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "RCTConvert+UIBarButtonItem.m"; sourceTree = "<group>"; };
84BC2EAB229EE9FF00A386C6 /* RCTConvert+PSPDFViewMode.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "RCTConvert+PSPDFViewMode.h"; sourceTree = "<group>"; };
84BC2EAC229EE9FF00A386C6 /* RCTConvert+PSPDFViewMode.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "RCTConvert+PSPDFViewMode.m"; sourceTree = "<group>"; };
B783BA3221C3F55300FD981A /* RCTConvert+PSPDFAnnotationToolbarConfiguration.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "RCTConvert+PSPDFAnnotationToolbarConfiguration.h"; sourceTree = "<group>"; };
B783BA3321C3F55300FD981A /* RCTConvert+PSPDFAnnotationToolbarConfiguration.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "RCTConvert+PSPDFAnnotationToolbarConfiguration.m"; sourceTree = "<group>"; };
F84F8B182032D54F00153D9E /* RCTPSPDFKitView.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RCTPSPDFKitView.m; sourceTree = "<group>"; };
Expand Down Expand Up @@ -82,6 +88,10 @@
657278101D86AEC600A5E1A8 /* RCTConvert+PSPDFDocument.m */,
B783BA3221C3F55300FD981A /* RCTConvert+PSPDFAnnotationToolbarConfiguration.h */,
B783BA3321C3F55300FD981A /* RCTConvert+PSPDFAnnotationToolbarConfiguration.m */,
84BC2EAB229EE9FF00A386C6 /* RCTConvert+PSPDFViewMode.h */,
84BC2EAC229EE9FF00A386C6 /* RCTConvert+PSPDFViewMode.m */,
84694AA622AFC7510077FD01 /* RCTConvert+UIBarButtonItem.h */,
84694AA722AFC7510077FD01 /* RCTConvert+UIBarButtonItem.m */,
);
path = Converters;
sourceTree = "<group>";
Expand Down Expand Up @@ -167,9 +177,11 @@
F8C1A2E5202DCC9700E98192 /* RCTPSPDFKitViewManager.m in Sources */,
84545BA4210A5CCF00FBB0A7 /* RCTConvert+PSPDFAnnotation.m in Sources */,
6540D1841D89D22E00B8F94F /* RCTPSPDFKitManager.m in Sources */,
84694AA822AFC7510077FD01 /* RCTConvert+UIBarButtonItem.m in Sources */,
B783BA3421C3F55300FD981A /* RCTConvert+PSPDFAnnotationToolbarConfiguration.m in Sources */,
F84F8B192032D54F00153D9E /* RCTPSPDFKitView.m in Sources */,
6572780C1D86AE7300A5E1A8 /* RCTConvert+PSPDFConfiguration.m in Sources */,
84BC2EAD229EE9FF00A386C6 /* RCTConvert+PSPDFViewMode.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
18 changes: 18 additions & 0 deletions ios/RCTPSPDFKit/Converters/RCTConvert+PSPDFViewMode.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//
// Copyright © 2019 PSPDFKit GmbH. All rights reserved.
//
// THIS SOURCE CODE AND ANY ACCOMPANYING DOCUMENTATION ARE PROTECTED BY INTERNATIONAL COPYRIGHT LAW
// AND MAY NOT BE RESOLD OR REDISTRIBUTED. USAGE IS BOUND TO THE PSPDFKIT LICENSE AGREEMENT.
// UNAUTHORIZED REPRODUCTION OR DISTRIBUTION IS SUBJECT TO CIVIL AND CRIMINAL PENALTIES.
// This notice may not be removed from this file.
//

#import <React/RCTConvert.h>
@import PSPDFKit;
@import PSPDFKitUI;

@interface RCTConvert (PSPDFViewMode)

+ (PSPDFViewMode)PSPDFViewMode:(NSString *)viewMode;

@end
26 changes: 26 additions & 0 deletions ios/RCTPSPDFKit/Converters/RCTConvert+PSPDFViewMode.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//
// Copyright © 2019 PSPDFKit GmbH. All rights reserved.
//
// THIS SOURCE CODE AND ANY ACCOMPANYING DOCUMENTATION ARE PROTECTED BY INTERNATIONAL COPYRIGHT LAW
// AND MAY NOT BE RESOLD OR REDISTRIBUTED. USAGE IS BOUND TO THE PSPDFKIT LICENSE AGREEMENT.
// UNAUTHORIZED REPRODUCTION OR DISTRIBUTION IS SUBJECT TO CIVIL AND CRIMINAL PENALTIES.
// This notice may not be removed from this file.
//

#import "RCTConvert+PSPDFViewMode.h"

@implementation RCTConvert (PSPDFViewMode)

+ (PSPDFViewMode)PSPDFViewMode:(NSString *)viewMode {
if ([viewMode isEqualToString:@"document"]) {
return PSPDFViewModeDocument;
} else if ([viewMode isEqualToString:@"thumbnails"]) {
return PSPDFViewModeThumbnails;
} else if ([viewMode isEqualToString:@"documentEditor"]) {
return PSPDFViewModeDocumentEditor;;
} else {
return PSPDFViewModeDocument;
}
}

@end
19 changes: 19 additions & 0 deletions ios/RCTPSPDFKit/Converters/RCTConvert+UIBarButtonItem.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//
// Copyright © 2019 PSPDFKit GmbH. All rights reserved.
//
// THIS SOURCE CODE AND ANY ACCOMPANYING DOCUMENTATION ARE PROTECTED BY INTERNATIONAL COPYRIGHT LAW
// AND MAY NOT BE RESOLD OR REDISTRIBUTED. USAGE IS BOUND TO THE PSPDFKIT LICENSE AGREEMENT.
// UNAUTHORIZED REPRODUCTION OR DISTRIBUTION IS SUBJECT TO CIVIL AND CRIMINAL PENALTIES.
// This notice may not be removed from this file.
//

#import <React/RCTConvert.h>
@import PSPDFKit;
@import PSPDFKitUI;

@interface RCTConvert (UIBarButtonItem)

+ (NSString *)stringBarButtonItemFrom:(UIBarButtonItem *)barButtonItem forViewController:(PSPDFViewController *)pdfController;
+ (UIBarButtonItem *)uiBarButtonItemFrom:(NSString *)barButtonItem forViewController:(PSPDFViewController *)pdfController;

@end
Loading