Skip to content

Commit

Permalink
Merge pull request #255 from PSPDFKit/rad/toolbarTitle-ios
Browse files Browse the repository at this point in the history
Add `toolbarTitle` Javascript API to override the iOS toolbar title
  • Loading branch information
radazzouz authored Jul 16, 2019
2 parents ba1d940 + 4a83969 commit 610e292
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 16 deletions.
38 changes: 26 additions & 12 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ class PSPDFKitView extends React.Component {
if (Platform.OS === "android") {
UIManager.dispatchViewManagerCommand(
findNodeHandle(this.refs.pdfView),
this._getViewManagerConfig('RCTPSPDFKitView').Commands.enterAnnotationCreationMode,
this._getViewManagerConfig("RCTPSPDFKitView").Commands
.enterAnnotationCreationMode,
[]
);
} else if (Platform.OS === "ios") {
Expand All @@ -117,7 +118,8 @@ class PSPDFKitView extends React.Component {
if (Platform.OS === "android") {
UIManager.dispatchViewManagerCommand(
findNodeHandle(this.refs.pdfView),
this._getViewManagerConfig('RCTPSPDFKitView').Commands.exitCurrentlyActiveMode,
this._getViewManagerConfig("RCTPSPDFKitView").Commands
.exitCurrentlyActiveMode,
[]
);
} else if (Platform.OS === "ios") {
Expand All @@ -134,7 +136,8 @@ class PSPDFKitView extends React.Component {
if (Platform.OS === "android") {
UIManager.dispatchViewManagerCommand(
findNodeHandle(this.refs.pdfView),
this._getViewManagerConfig('RCTPSPDFKitView').Commands.saveCurrentDocument,
this._getViewManagerConfig("RCTPSPDFKitView").Commands
.saveCurrentDocument,
[]
);
} else if (Platform.OS === "ios") {
Expand Down Expand Up @@ -165,7 +168,7 @@ class PSPDFKitView extends React.Component {

UIManager.dispatchViewManagerCommand(
findNodeHandle(this.refs.pdfView),
this._getViewManagerConfig('RCTPSPDFKitView').Commands.getAnnotations,
this._getViewManagerConfig("RCTPSPDFKitView").Commands.getAnnotations,
[requestId, pageIndex, type]
);

Expand All @@ -188,7 +191,7 @@ class PSPDFKitView extends React.Component {
if (Platform.OS === "android") {
UIManager.dispatchViewManagerCommand(
findNodeHandle(this.refs.pdfView),
this._getViewManagerConfig('RCTPSPDFKitView').Commands.addAnnotation,
this._getViewManagerConfig("RCTPSPDFKitView").Commands.addAnnotation,
[annotation]
);
} else if (Platform.OS === "ios") {
Expand All @@ -208,7 +211,7 @@ class PSPDFKitView extends React.Component {
if (Platform.OS === "android") {
UIManager.dispatchViewManagerCommand(
findNodeHandle(this.refs.pdfView),
this._getViewManagerConfig('RCTPSPDFKitView').Commands.removeAnnotation,
this._getViewManagerConfig("RCTPSPDFKitView").Commands.removeAnnotation,
[annotation]
);
} else if (Platform.OS === "ios") {
Expand Down Expand Up @@ -236,7 +239,8 @@ class PSPDFKitView extends React.Component {

UIManager.dispatchViewManagerCommand(
findNodeHandle(this.refs.pdfView),
this._getViewManagerConfig('RCTPSPDFKitView').Commands.getAllUnsavedAnnotations,
this._getViewManagerConfig("RCTPSPDFKitView").Commands
.getAllUnsavedAnnotations,
[requestId]
);

Expand All @@ -257,7 +261,7 @@ class PSPDFKitView extends React.Component {
if (Platform.OS === "android") {
UIManager.dispatchViewManagerCommand(
findNodeHandle(this.refs.pdfView),
this._getViewManagerConfig('RCTPSPDFKitView').Commands.addAnnotations,
this._getViewManagerConfig("RCTPSPDFKitView").Commands.addAnnotations,
[annotations]
);
} else if (Platform.OS === "ios") {
Expand Down Expand Up @@ -288,7 +292,8 @@ class PSPDFKitView extends React.Component {

UIManager.dispatchViewManagerCommand(
findNodeHandle(this.refs.pdfView),
this._getViewManagerConfig('RCTPSPDFKitView').Commands.getFormFieldValue,
this._getViewManagerConfig("RCTPSPDFKitView").Commands
.getFormFieldValue,
[requestId, fullyQualifiedName]
);

Expand All @@ -311,7 +316,8 @@ class PSPDFKitView extends React.Component {
if (Platform.OS === "android") {
UIManager.dispatchViewManagerCommand(
findNodeHandle(this.refs.pdfView),
this._getViewManagerConfig('RCTPSPDFKitView').Commands.setFormFieldValue,
this._getViewManagerConfig("RCTPSPDFKitView").Commands
.setFormFieldValue,
[fullyQualifiedName, value]
);
} else if (Platform.OS === "ios") {
Expand Down Expand Up @@ -398,7 +404,7 @@ class PSPDFKitView extends React.Component {
};

_getViewManagerConfig = viewManagerName => {
const version = NativeModules.PlatformConstants.reactNativeVersion.minor
const version = NativeModules.PlatformConstants.reactNativeVersion.minor;
if (version >= 58) {
return UIManager.getViewManagerConfig(viewManagerName);
} else {
Expand Down Expand Up @@ -531,7 +537,15 @@ PSPDFKitView.propTypes = {
*
* @platform ios
*/
rightBarButtonItems: PropTypes.array
rightBarButtonItems: PropTypes.array,
/**
* toolbarTitle: Can be used to specfiy a custom toolbar title on iOS by setting the `title` property of the `PSPDFViewController`.
* Note: You need to set `showDocumentLabel`, `useParentNavigationBar`, and `allowToolbarTitleChange` to false in your Configuration before setting the custom title.
* See `ConfiguredPDFViewComponent` in https://github.com/PSPDFKit/react-native/blob/master/samples/Catalog/Catalog.ios.js
*
* @platform ios
*/
toolbarTitle: PropTypes.string
};

if (Platform.OS === "ios" || Platform.OS === "android") {
Expand Down
6 changes: 6 additions & 0 deletions ios/RCTPSPDFKit/RCTPSPDFKitViewManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ @implementation RCTPSPDFKitViewManager
}
}

RCT_CUSTOM_VIEW_PROPERTY(toolbarTitle, NSString, RCTPSPDFKitView) {
if (json) {
view.pdfController.title = json;
}
}

RCT_EXPORT_VIEW_PROPERTY(hideNavigationBar, BOOL)

RCT_EXPORT_VIEW_PROPERTY(disableDefaultActionForTappedAnnotations, BOOL)
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-native-pspdfkit",
"version": "1.24.5",
"version": "1.24.6",
"description": "A React Native module for the PSPDFKit library.",
"keywords": [
"react native",
Expand Down
5 changes: 4 additions & 1 deletion samples/Catalog/Catalog.ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,11 @@ class ConfiguredPDFViewComponent extends Component {
configuration={{
backgroundColor: processColor("lightgrey"),
showThumbnailBar: "scrubberBar",
showDocumentLabel: true
showDocumentLabel: false,
useParentNavigationBar: false,
allowToolbarTitleChange: false
}}
toolbarTitle={"Custom Title"}
style={{ flex: 1, color: pspdfkitColor }}
/>
</View>
Expand Down
2 changes: 1 addition & 1 deletion samples/Catalog/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Catalog",
"version": "1.24.5",
"version": "1.24.6",
"private": true,
"scripts": {
"start": "node node_modules/react-native/local-cli/cli.js start"
Expand Down

0 comments on commit 610e292

Please sign in to comment.