Skip to content

Commit accdd0b

Browse files
authored
Merge pull request #233 from PSPDFKit/rad/customize-toolbar-ios
Adds Javascript API to customize the toolbar on iOS
2 parents c31d3c6 + 0ca352b commit accdd0b

File tree

13 files changed

+478
-29
lines changed

13 files changed

+478
-29
lines changed

index.js

Lines changed: 106 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ class PSPDFKitView extends React.Component {
2424
if (Platform.OS === "ios" || Platform.OS === "android") {
2525
const onCloseButtonPressedHandler = this.props.onCloseButtonPressed
2626
? event => {
27-
this.props.onCloseButtonPressed(event.nativeEvent);
28-
}
27+
this.props.onCloseButtonPressed(event.nativeEvent);
28+
}
2929
: null;
3030
return (
3131
<RCTPSPDFKitView
@@ -89,7 +89,7 @@ class PSPDFKitView extends React.Component {
8989
/**
9090
* Enters the annotation creation mode, showing the annotation creation toolbar.
9191
*/
92-
enterAnnotationCreationMode = function () {
92+
enterAnnotationCreationMode = function() {
9393
if (Platform.OS === "android") {
9494
UIManager.dispatchViewManagerCommand(
9595
findNodeHandle(this.refs.pdfView),
@@ -106,7 +106,7 @@ class PSPDFKitView extends React.Component {
106106
/**
107107
* Exits the currently active mode, hiding all toolbars.
108108
*/
109-
exitCurrentlyActiveMode = function () {
109+
exitCurrentlyActiveMode = function() {
110110
if (Platform.OS === "android") {
111111
UIManager.dispatchViewManagerCommand(
112112
findNodeHandle(this.refs.pdfView),
@@ -123,7 +123,7 @@ class PSPDFKitView extends React.Component {
123123
/**
124124
* Saves the currently opened document.
125125
*/
126-
saveCurrentDocument = function () {
126+
saveCurrentDocument = function() {
127127
if (Platform.OS === "android") {
128128
UIManager.dispatchViewManagerCommand(
129129
findNodeHandle(this.refs.pdfView),
@@ -146,13 +146,13 @@ class PSPDFKitView extends React.Component {
146146
* Returns a promise resolving an array with the following structure:
147147
* {'annotations' : [instantJson]}
148148
*/
149-
getAnnotations = function (pageIndex, type) {
149+
getAnnotations = function(pageIndex, type) {
150150
if (Platform.OS === "android") {
151151
let requestId = this._nextRequestId++;
152152
let requestMap = this._requestMap;
153153

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

@@ -177,7 +177,7 @@ class PSPDFKitView extends React.Component {
177177
*
178178
* @param annotation InstantJson of the annotation to add.
179179
*/
180-
addAnnotation = function (annotation) {
180+
addAnnotation = function(annotation) {
181181
if (Platform.OS === "android") {
182182
UIManager.dispatchViewManagerCommand(
183183
findNodeHandle(this.refs.pdfView),
@@ -197,7 +197,7 @@ class PSPDFKitView extends React.Component {
197197
*
198198
* @param annotation InstantJson of the annotation to remove.
199199
*/
200-
removeAnnotation = function (annotation) {
200+
removeAnnotation = function(annotation) {
201201
if (Platform.OS === "android") {
202202
UIManager.dispatchViewManagerCommand(
203203
findNodeHandle(this.refs.pdfView),
@@ -217,13 +217,13 @@ class PSPDFKitView extends React.Component {
217217
*
218218
* Returns a promise resolving to document instant json (https://pspdfkit.com/guides/android/current/importing-exporting/instant-json/#instant-document-json-api-a56628).
219219
*/
220-
getAllUnsavedAnnotations = function () {
220+
getAllUnsavedAnnotations = function() {
221221
if (Platform.OS === "android") {
222222
let requestId = this._nextRequestId++;
223223
let requestMap = this._requestMap;
224224

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

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

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

@@ -300,7 +300,7 @@ class PSPDFKitView extends React.Component {
300300
* @param fullyQualifiedName The fully qualified name of the form element.
301301
* @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'.
302302
*/
303-
setFormFieldValue = function (fullyQualifiedName, value) {
303+
setFormFieldValue = function(fullyQualifiedName, value) {
304304
if (Platform.OS === "android") {
305305
UIManager.dispatchViewManagerCommand(
306306
findNodeHandle(this.refs.pdfView),
@@ -315,6 +315,80 @@ class PSPDFKitView extends React.Component {
315315
);
316316
}
317317
};
318+
/**
319+
* Set the left bar button items for the specified view mode.
320+
* Note: The same button item cannot be added to both the left and right bar button items simultaneously.
321+
*
322+
* @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
323+
* @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.
324+
* @param animated The animated flag.
325+
*
326+
* @platform ios
327+
*/
328+
setLeftBarButtonItems = function(items, viewMode, animated) {
329+
if (Platform.OS === "ios") {
330+
NativeModules.PSPDFKitViewManager.setLeftBarButtonItems(
331+
items,
332+
viewMode,
333+
animated,
334+
findNodeHandle(this.refs.pdfView)
335+
);
336+
}
337+
};
338+
/**
339+
* Get the left bar button items for the specified view mode.
340+
*
341+
* @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.
342+
*
343+
* Returns a promise resolving an array with the following structure:
344+
* ['outlineButtonItem', 'searchButtonItem'] or a dictionary with the following error {'error' : 'Failed to get the left bar button items.'}
345+
* @platform ios
346+
*/
347+
getLeftBarButtonItemsForViewMode = function(viewMode) {
348+
if (Platform.OS === "ios") {
349+
return NativeModules.PSPDFKitViewManager.getLeftBarButtonItemsForViewMode(
350+
viewMode,
351+
findNodeHandle(this.refs.pdfView)
352+
);
353+
}
354+
};
355+
/**
356+
* Set the right bar button items for the specified view mode.
357+
* Note: The same button item cannot be added to both the left and right bar button items simultaneously.
358+
*
359+
* @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
360+
* @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.
361+
* @param animated The animated flag.
362+
*
363+
* @platform ios
364+
*/
365+
setRightBarButtonItems = function(items, viewMode, animated) {
366+
if (Platform.OS === "ios") {
367+
NativeModules.PSPDFKitViewManager.setRightBarButtonItems(
368+
items,
369+
viewMode,
370+
animated,
371+
findNodeHandle(this.refs.pdfView)
372+
);
373+
}
374+
};
375+
/**
376+
* Get the right bar button items for the specified view mode.
377+
*
378+
* @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.
379+
*
380+
* Returns a promise resolving an array with the following structure:
381+
* ['annotationButtonItem', 'documentEditorButtonItem'] or a dictionary with the following error {'error' : 'Failed to get the right bar button items.'}
382+
* @platform ios
383+
*/
384+
getRightBarButtonItemsForViewMode = function(viewMode) {
385+
if (Platform.OS === "ios") {
386+
return NativeModules.PSPDFKitViewManager.getRightBarButtonItemsForViewMode(
387+
viewMode,
388+
findNodeHandle(this.refs.pdfView)
389+
);
390+
}
391+
};
318392
}
319393

320394
PSPDFKitView.propTypes = {
@@ -425,7 +499,23 @@ PSPDFKitView.propTypes = {
425499
/**
426500
* menuItemGrouping: Can be used to specfiy a custom grouping for the menu items in the annotation creation toolbar.
427501
*/
428-
menuItemGrouping: PropTypes.array
502+
menuItemGrouping: PropTypes.array,
503+
/**
504+
* leftBarButtonItems: Can be used to specfiy an array of the left button items.
505+
* Note: The same button item cannot be added to both the left and right bar button items simultaneously.
506+
* The full list of button items: https://pspdfkit.com/api/ios/Classes/PSPDFViewController.html#/Toolbar%20button%20items
507+
*
508+
* @platform ios
509+
*/
510+
leftBarButtonItems: PropTypes.array,
511+
/**
512+
* rightBarButtonItems: Can be used to specfiy an array of the right button items.
513+
* Note: The same button item cannot be added to both the left and right bar button items simultaneously.
514+
* The full list of button items: https://pspdfkit.com/api/ios/Classes/PSPDFViewController.html#/Toolbar%20button%20items
515+
*
516+
* @platform ios
517+
*/
518+
rightBarButtonItems: PropTypes.array
429519
};
430520

431521
if (Platform.OS === "ios" || Platform.OS === "android") {

ios/RCTPSPDFKit.xcodeproj/project.pbxproj

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
6572780C1D86AE7300A5E1A8 /* RCTConvert+PSPDFConfiguration.m in Sources */ = {isa = PBXBuildFile; fileRef = 657278071D86AE7300A5E1A8 /* RCTConvert+PSPDFConfiguration.m */; };
1212
657278111D86AEC600A5E1A8 /* RCTConvert+PSPDFDocument.m in Sources */ = {isa = PBXBuildFile; fileRef = 657278101D86AEC600A5E1A8 /* RCTConvert+PSPDFDocument.m */; };
1313
84545BA4210A5CCF00FBB0A7 /* RCTConvert+PSPDFAnnotation.m in Sources */ = {isa = PBXBuildFile; fileRef = 84545BA2210A5CCF00FBB0A7 /* RCTConvert+PSPDFAnnotation.m */; };
14+
84694AA822AFC7510077FD01 /* RCTConvert+UIBarButtonItem.m in Sources */ = {isa = PBXBuildFile; fileRef = 84694AA722AFC7510077FD01 /* RCTConvert+UIBarButtonItem.m */; };
15+
84BC2EAD229EE9FF00A386C6 /* RCTConvert+PSPDFViewMode.m in Sources */ = {isa = PBXBuildFile; fileRef = 84BC2EAC229EE9FF00A386C6 /* RCTConvert+PSPDFViewMode.m */; };
1416
B783BA3421C3F55300FD981A /* RCTConvert+PSPDFAnnotationToolbarConfiguration.m in Sources */ = {isa = PBXBuildFile; fileRef = B783BA3321C3F55300FD981A /* RCTConvert+PSPDFAnnotationToolbarConfiguration.m */; };
1517
F84F8B192032D54F00153D9E /* RCTPSPDFKitView.m in Sources */ = {isa = PBXBuildFile; fileRef = F84F8B182032D54F00153D9E /* RCTPSPDFKitView.m */; };
1618
F8C1A2E5202DCC9700E98192 /* RCTPSPDFKitViewManager.m in Sources */ = {isa = PBXBuildFile; fileRef = F8C1A2E4202DCC9700E98192 /* RCTPSPDFKitViewManager.m */; };
@@ -38,6 +40,10 @@
3840
657278101D86AEC600A5E1A8 /* RCTConvert+PSPDFDocument.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "RCTConvert+PSPDFDocument.m"; sourceTree = "<group>"; };
3941
84545BA2210A5CCF00FBB0A7 /* RCTConvert+PSPDFAnnotation.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "RCTConvert+PSPDFAnnotation.m"; sourceTree = "<group>"; };
4042
84545BA3210A5CCF00FBB0A7 /* RCTConvert+PSPDFAnnotation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "RCTConvert+PSPDFAnnotation.h"; sourceTree = "<group>"; };
43+
84694AA622AFC7510077FD01 /* RCTConvert+UIBarButtonItem.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "RCTConvert+UIBarButtonItem.h"; sourceTree = "<group>"; };
44+
84694AA722AFC7510077FD01 /* RCTConvert+UIBarButtonItem.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "RCTConvert+UIBarButtonItem.m"; sourceTree = "<group>"; };
45+
84BC2EAB229EE9FF00A386C6 /* RCTConvert+PSPDFViewMode.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "RCTConvert+PSPDFViewMode.h"; sourceTree = "<group>"; };
46+
84BC2EAC229EE9FF00A386C6 /* RCTConvert+PSPDFViewMode.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "RCTConvert+PSPDFViewMode.m"; sourceTree = "<group>"; };
4147
B783BA3221C3F55300FD981A /* RCTConvert+PSPDFAnnotationToolbarConfiguration.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "RCTConvert+PSPDFAnnotationToolbarConfiguration.h"; sourceTree = "<group>"; };
4248
B783BA3321C3F55300FD981A /* RCTConvert+PSPDFAnnotationToolbarConfiguration.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "RCTConvert+PSPDFAnnotationToolbarConfiguration.m"; sourceTree = "<group>"; };
4349
F84F8B182032D54F00153D9E /* RCTPSPDFKitView.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RCTPSPDFKitView.m; sourceTree = "<group>"; };
@@ -82,6 +88,10 @@
8288
657278101D86AEC600A5E1A8 /* RCTConvert+PSPDFDocument.m */,
8389
B783BA3221C3F55300FD981A /* RCTConvert+PSPDFAnnotationToolbarConfiguration.h */,
8490
B783BA3321C3F55300FD981A /* RCTConvert+PSPDFAnnotationToolbarConfiguration.m */,
91+
84BC2EAB229EE9FF00A386C6 /* RCTConvert+PSPDFViewMode.h */,
92+
84BC2EAC229EE9FF00A386C6 /* RCTConvert+PSPDFViewMode.m */,
93+
84694AA622AFC7510077FD01 /* RCTConvert+UIBarButtonItem.h */,
94+
84694AA722AFC7510077FD01 /* RCTConvert+UIBarButtonItem.m */,
8595
);
8696
path = Converters;
8797
sourceTree = "<group>";
@@ -167,9 +177,11 @@
167177
F8C1A2E5202DCC9700E98192 /* RCTPSPDFKitViewManager.m in Sources */,
168178
84545BA4210A5CCF00FBB0A7 /* RCTConvert+PSPDFAnnotation.m in Sources */,
169179
6540D1841D89D22E00B8F94F /* RCTPSPDFKitManager.m in Sources */,
180+
84694AA822AFC7510077FD01 /* RCTConvert+UIBarButtonItem.m in Sources */,
170181
B783BA3421C3F55300FD981A /* RCTConvert+PSPDFAnnotationToolbarConfiguration.m in Sources */,
171182
F84F8B192032D54F00153D9E /* RCTPSPDFKitView.m in Sources */,
172183
6572780C1D86AE7300A5E1A8 /* RCTConvert+PSPDFConfiguration.m in Sources */,
184+
84BC2EAD229EE9FF00A386C6 /* RCTConvert+PSPDFViewMode.m in Sources */,
173185
);
174186
runOnlyForDeploymentPostprocessing = 0;
175187
};
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//
2+
// Copyright © 2019 PSPDFKit GmbH. All rights reserved.
3+
//
4+
// THIS SOURCE CODE AND ANY ACCOMPANYING DOCUMENTATION ARE PROTECTED BY INTERNATIONAL COPYRIGHT LAW
5+
// AND MAY NOT BE RESOLD OR REDISTRIBUTED. USAGE IS BOUND TO THE PSPDFKIT LICENSE AGREEMENT.
6+
// UNAUTHORIZED REPRODUCTION OR DISTRIBUTION IS SUBJECT TO CIVIL AND CRIMINAL PENALTIES.
7+
// This notice may not be removed from this file.
8+
//
9+
10+
#import <React/RCTConvert.h>
11+
@import PSPDFKit;
12+
@import PSPDFKitUI;
13+
14+
@interface RCTConvert (PSPDFViewMode)
15+
16+
+ (PSPDFViewMode)PSPDFViewMode:(NSString *)viewMode;
17+
18+
@end
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//
2+
// Copyright © 2019 PSPDFKit GmbH. All rights reserved.
3+
//
4+
// THIS SOURCE CODE AND ANY ACCOMPANYING DOCUMENTATION ARE PROTECTED BY INTERNATIONAL COPYRIGHT LAW
5+
// AND MAY NOT BE RESOLD OR REDISTRIBUTED. USAGE IS BOUND TO THE PSPDFKIT LICENSE AGREEMENT.
6+
// UNAUTHORIZED REPRODUCTION OR DISTRIBUTION IS SUBJECT TO CIVIL AND CRIMINAL PENALTIES.
7+
// This notice may not be removed from this file.
8+
//
9+
10+
#import "RCTConvert+PSPDFViewMode.h"
11+
12+
@implementation RCTConvert (PSPDFViewMode)
13+
14+
+ (PSPDFViewMode)PSPDFViewMode:(NSString *)viewMode {
15+
if ([viewMode isEqualToString:@"document"]) {
16+
return PSPDFViewModeDocument;
17+
} else if ([viewMode isEqualToString:@"thumbnails"]) {
18+
return PSPDFViewModeThumbnails;
19+
} else if ([viewMode isEqualToString:@"documentEditor"]) {
20+
return PSPDFViewModeDocumentEditor;;
21+
} else {
22+
return PSPDFViewModeDocument;
23+
}
24+
}
25+
26+
@end
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//
2+
// Copyright © 2019 PSPDFKit GmbH. All rights reserved.
3+
//
4+
// THIS SOURCE CODE AND ANY ACCOMPANYING DOCUMENTATION ARE PROTECTED BY INTERNATIONAL COPYRIGHT LAW
5+
// AND MAY NOT BE RESOLD OR REDISTRIBUTED. USAGE IS BOUND TO THE PSPDFKIT LICENSE AGREEMENT.
6+
// UNAUTHORIZED REPRODUCTION OR DISTRIBUTION IS SUBJECT TO CIVIL AND CRIMINAL PENALTIES.
7+
// This notice may not be removed from this file.
8+
//
9+
10+
#import <React/RCTConvert.h>
11+
@import PSPDFKit;
12+
@import PSPDFKitUI;
13+
14+
@interface RCTConvert (UIBarButtonItem)
15+
16+
+ (NSString *)stringBarButtonItemFrom:(UIBarButtonItem *)barButtonItem forViewController:(PSPDFViewController *)pdfController;
17+
+ (UIBarButtonItem *)uiBarButtonItemFrom:(NSString *)barButtonItem forViewController:(PSPDFViewController *)pdfController;
18+
19+
@end

0 commit comments

Comments
 (0)