Skip to content

Commit

Permalink
UWP: Remove Annotation (#222)
Browse files Browse the repository at this point in the history
Brings UWP removeAnnotation API inline with iOS and Android.
Also fixes small typo with getAnnotations JSON reply.
  • Loading branch information
nickwinder authored May 20, 2019
1 parent 847cb25 commit 590f30a
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 7 deletions.
26 changes: 26 additions & 0 deletions index.windows.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,32 @@ class PSPDFKitView extends React.Component {
return promise;
};

/**
* Removes an annotation to the current document.
*
* @param annotation InstantJson of the annotation to remove with the format of
* https://pspdfkit.com/guides/windows/current/importing-exporting/instant-json/#instant-annotation-json-api
*
* @returns a promise resolving if successful or rejects if an error occurs with and error message
*/
removeAnnotation(annotation) {
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((resolve, reject) => {
requestMap[requestId] = {resolve: resolve, reject: reject};
});

UIManager.dispatchViewManagerCommand(
findNodeHandle(this.refs.pdfView),
UIManager.RCTPSPDFKitView.Commands.removeAnnotation,
[requestId, annotation]
);

return promise;
};

/**
* Gets toolbar items currently shown.
*
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.23.10",
"version": "1.23.11",
"description": "A React Native module for the PSPDFKit library.",
"keywords": [
"react native",
Expand Down
23 changes: 20 additions & 3 deletions samples/Catalog/Catalog.windows.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
TouchableHighlight,
NativeModules,
Button,
Linking
Linking
} from "react-native";
import {StackNavigator} from "react-navigation";
import PSPDFKitView from "react-native-pspdfkit";
Expand Down Expand Up @@ -406,7 +406,7 @@ class PdfViewInstantJsonScreen extends Component<{}> {
alert(JSON.stringify(annotations));
});
}}
title="Get annotations"
title="Get Annotations"
/>
</View>
<View style={{marginLeft: 10}}>
Expand All @@ -419,7 +419,24 @@ class PdfViewInstantJsonScreen extends Component<{}> {
alert(error);
});
}}
title="Add annotation"
title="Add Annotation"
/>
</View>
<View style={{marginLeft: 10}}>
<Button
onPress={() => {
this.refs.pdfView.getAnnotations(0).then(result => {
if (result.annotations !== undefined && result.annotations.length > 0) {
// Removes the ink annotation if added with Add annotation button rejects if not present
this.refs.pdfView.removeAnnotation(result.annotations[0]).then(() => {
alert("Annotation removal was successful.");
}).catch(error => {
alert(error);
});
}
});
}}
title="Remove Annotation"
/>
</View>
</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.23.10",
"version": "1.23.11",
"private": true,
"scripts": {
"start": "node node_modules/react-native/local-cli/cli.js start"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public PdfViewDataReturnedEvent(int viewId, int requestId, IEnumerable<IAnnotati

var annotations = new JObject
{
{ "annoations",annotationsSerialized}
{ "annotations",annotationsSerialized}
};
_payload.Add("result", annotations);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,17 @@ await Pdfview.Document.CreateAnnotationAsync(
);
}

internal async Task RemoveAnnotation(int requestId, string annotationJsonString)
{
await RunOperationAndFireEvent(requestId,
async () =>
{
var annotation = Factory.FromJson(JsonObject.Parse(annotationJsonString));
await Pdfview.Document.DeleteAnnotationAsync(annotation.Id);
}
);
}

internal async Task SetInteractionMode(int requestId, InteractionMode interactionMode)
{
await RunOperationAndFireEvent(requestId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public class PSPDFKitViewManger : SimpleViewManager<PDFViewPage>
private const int COMMAND_ADD_ANNOTATION = 5;
private const int COMMAND_GET_TOOLBAR_ITEMS = 6;
private const int COMMAND_SET_TOOLBAR_ITEMS = 7;
private const int COMMAND_REMOVE_ANNOTATION = 8;

internal readonly PDFViewPage PdfViewPage = new PDFViewPage();

Expand Down Expand Up @@ -80,6 +81,9 @@ public void SetHideNavigationBar(PDFViewPage view, bool hideNavigationBar)
{
"addAnnotation", COMMAND_ADD_ANNOTATION
},
{
"removeAnnotation", COMMAND_REMOVE_ANNOTATION
},
{
"getToolbarItems", COMMAND_GET_TOOLBAR_ITEMS
},
Expand Down Expand Up @@ -107,6 +111,9 @@ public override async void ReceiveCommand(PDFViewPage view, int commandId, JArra
case COMMAND_ADD_ANNOTATION:
await PdfViewPage.CreateAnnotation(args[0].Value<int>(), args[1].ToString());
break;
case COMMAND_REMOVE_ANNOTATION:
await PdfViewPage.RemoveAnnotation(args[0].Value<int>(), args[1].ToString());
break;
case COMMAND_GET_TOOLBAR_ITEMS:
PdfViewPage.GetToolbarItems(args[0].Value<int>());
break;
Expand Down

0 comments on commit 590f30a

Please sign in to comment.