Skip to content

Commit 610e292

Browse files
authored
Merge pull request #255 from PSPDFKit/rad/toolbarTitle-ios
Add `toolbarTitle` Javascript API to override the iOS toolbar title
2 parents ba1d940 + 4a83969 commit 610e292

File tree

6 files changed

+39
-16
lines changed

6 files changed

+39
-16
lines changed

index.js

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ class PSPDFKitView extends React.Component {
100100
if (Platform.OS === "android") {
101101
UIManager.dispatchViewManagerCommand(
102102
findNodeHandle(this.refs.pdfView),
103-
this._getViewManagerConfig('RCTPSPDFKitView').Commands.enterAnnotationCreationMode,
103+
this._getViewManagerConfig("RCTPSPDFKitView").Commands
104+
.enterAnnotationCreationMode,
104105
[]
105106
);
106107
} else if (Platform.OS === "ios") {
@@ -117,7 +118,8 @@ class PSPDFKitView extends React.Component {
117118
if (Platform.OS === "android") {
118119
UIManager.dispatchViewManagerCommand(
119120
findNodeHandle(this.refs.pdfView),
120-
this._getViewManagerConfig('RCTPSPDFKitView').Commands.exitCurrentlyActiveMode,
121+
this._getViewManagerConfig("RCTPSPDFKitView").Commands
122+
.exitCurrentlyActiveMode,
121123
[]
122124
);
123125
} else if (Platform.OS === "ios") {
@@ -134,7 +136,8 @@ class PSPDFKitView extends React.Component {
134136
if (Platform.OS === "android") {
135137
UIManager.dispatchViewManagerCommand(
136138
findNodeHandle(this.refs.pdfView),
137-
this._getViewManagerConfig('RCTPSPDFKitView').Commands.saveCurrentDocument,
139+
this._getViewManagerConfig("RCTPSPDFKitView").Commands
140+
.saveCurrentDocument,
138141
[]
139142
);
140143
} else if (Platform.OS === "ios") {
@@ -165,7 +168,7 @@ class PSPDFKitView extends React.Component {
165168

166169
UIManager.dispatchViewManagerCommand(
167170
findNodeHandle(this.refs.pdfView),
168-
this._getViewManagerConfig('RCTPSPDFKitView').Commands.getAnnotations,
171+
this._getViewManagerConfig("RCTPSPDFKitView").Commands.getAnnotations,
169172
[requestId, pageIndex, type]
170173
);
171174

@@ -188,7 +191,7 @@ class PSPDFKitView extends React.Component {
188191
if (Platform.OS === "android") {
189192
UIManager.dispatchViewManagerCommand(
190193
findNodeHandle(this.refs.pdfView),
191-
this._getViewManagerConfig('RCTPSPDFKitView').Commands.addAnnotation,
194+
this._getViewManagerConfig("RCTPSPDFKitView").Commands.addAnnotation,
192195
[annotation]
193196
);
194197
} else if (Platform.OS === "ios") {
@@ -208,7 +211,7 @@ class PSPDFKitView extends React.Component {
208211
if (Platform.OS === "android") {
209212
UIManager.dispatchViewManagerCommand(
210213
findNodeHandle(this.refs.pdfView),
211-
this._getViewManagerConfig('RCTPSPDFKitView').Commands.removeAnnotation,
214+
this._getViewManagerConfig("RCTPSPDFKitView").Commands.removeAnnotation,
212215
[annotation]
213216
);
214217
} else if (Platform.OS === "ios") {
@@ -236,7 +239,8 @@ class PSPDFKitView extends React.Component {
236239

237240
UIManager.dispatchViewManagerCommand(
238241
findNodeHandle(this.refs.pdfView),
239-
this._getViewManagerConfig('RCTPSPDFKitView').Commands.getAllUnsavedAnnotations,
242+
this._getViewManagerConfig("RCTPSPDFKitView").Commands
243+
.getAllUnsavedAnnotations,
240244
[requestId]
241245
);
242246

@@ -257,7 +261,7 @@ class PSPDFKitView extends React.Component {
257261
if (Platform.OS === "android") {
258262
UIManager.dispatchViewManagerCommand(
259263
findNodeHandle(this.refs.pdfView),
260-
this._getViewManagerConfig('RCTPSPDFKitView').Commands.addAnnotations,
264+
this._getViewManagerConfig("RCTPSPDFKitView").Commands.addAnnotations,
261265
[annotations]
262266
);
263267
} else if (Platform.OS === "ios") {
@@ -288,7 +292,8 @@ class PSPDFKitView extends React.Component {
288292

289293
UIManager.dispatchViewManagerCommand(
290294
findNodeHandle(this.refs.pdfView),
291-
this._getViewManagerConfig('RCTPSPDFKitView').Commands.getFormFieldValue,
295+
this._getViewManagerConfig("RCTPSPDFKitView").Commands
296+
.getFormFieldValue,
292297
[requestId, fullyQualifiedName]
293298
);
294299

@@ -311,7 +316,8 @@ class PSPDFKitView extends React.Component {
311316
if (Platform.OS === "android") {
312317
UIManager.dispatchViewManagerCommand(
313318
findNodeHandle(this.refs.pdfView),
314-
this._getViewManagerConfig('RCTPSPDFKitView').Commands.setFormFieldValue,
319+
this._getViewManagerConfig("RCTPSPDFKitView").Commands
320+
.setFormFieldValue,
315321
[fullyQualifiedName, value]
316322
);
317323
} else if (Platform.OS === "ios") {
@@ -398,7 +404,7 @@ class PSPDFKitView extends React.Component {
398404
};
399405

400406
_getViewManagerConfig = viewManagerName => {
401-
const version = NativeModules.PlatformConstants.reactNativeVersion.minor
407+
const version = NativeModules.PlatformConstants.reactNativeVersion.minor;
402408
if (version >= 58) {
403409
return UIManager.getViewManagerConfig(viewManagerName);
404410
} else {
@@ -531,7 +537,15 @@ PSPDFKitView.propTypes = {
531537
*
532538
* @platform ios
533539
*/
534-
rightBarButtonItems: PropTypes.array
540+
rightBarButtonItems: PropTypes.array,
541+
/**
542+
* toolbarTitle: Can be used to specfiy a custom toolbar title on iOS by setting the `title` property of the `PSPDFViewController`.
543+
* Note: You need to set `showDocumentLabel`, `useParentNavigationBar`, and `allowToolbarTitleChange` to false in your Configuration before setting the custom title.
544+
* See `ConfiguredPDFViewComponent` in https://github.com/PSPDFKit/react-native/blob/master/samples/Catalog/Catalog.ios.js
545+
*
546+
* @platform ios
547+
*/
548+
toolbarTitle: PropTypes.string
535549
};
536550

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

ios/RCTPSPDFKit/RCTPSPDFKitViewManager.m

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,12 @@ @implementation RCTPSPDFKitViewManager
7373
}
7474
}
7575

76+
RCT_CUSTOM_VIEW_PROPERTY(toolbarTitle, NSString, RCTPSPDFKitView) {
77+
if (json) {
78+
view.pdfController.title = json;
79+
}
80+
}
81+
7682
RCT_EXPORT_VIEW_PROPERTY(hideNavigationBar, BOOL)
7783

7884
RCT_EXPORT_VIEW_PROPERTY(disableDefaultActionForTappedAnnotations, BOOL)

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-pspdfkit",
3-
"version": "1.24.5",
3+
"version": "1.24.6",
44
"description": "A React Native module for the PSPDFKit library.",
55
"keywords": [
66
"react native",

samples/Catalog/Catalog.ios.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,8 +251,11 @@ class ConfiguredPDFViewComponent extends Component {
251251
configuration={{
252252
backgroundColor: processColor("lightgrey"),
253253
showThumbnailBar: "scrubberBar",
254-
showDocumentLabel: true
254+
showDocumentLabel: false,
255+
useParentNavigationBar: false,
256+
allowToolbarTitleChange: false
255257
}}
258+
toolbarTitle={"Custom Title"}
256259
style={{ flex: 1, color: pspdfkitColor }}
257260
/>
258261
</View>

samples/Catalog/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "Catalog",
3-
"version": "1.24.5",
3+
"version": "1.24.6",
44
"private": true,
55
"scripts": {
66
"start": "node node_modules/react-native/local-cli/cli.js start"

0 commit comments

Comments
 (0)