Skip to content

Commit 590f30a

Browse files
authored
UWP: Remove Annotation (#222)
Brings UWP removeAnnotation API inline with iOS and Android. Also fixes small typo with getAnnotations JSON reply.
1 parent 847cb25 commit 590f30a

File tree

8 files changed

+68
-7
lines changed

8 files changed

+68
-7
lines changed

index.windows.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,32 @@ class PSPDFKitView extends React.Component {
179179
return promise;
180180
};
181181

182+
/**
183+
* Removes an annotation to the current document.
184+
*
185+
* @param annotation InstantJson of the annotation to remove with the format of
186+
* https://pspdfkit.com/guides/windows/current/importing-exporting/instant-json/#instant-annotation-json-api
187+
*
188+
* @returns a promise resolving if successful or rejects if an error occurs with and error message
189+
*/
190+
removeAnnotation(annotation) {
191+
let requestId = this._nextRequestId++;
192+
let requestMap = this._requestMap;
193+
194+
// We create a promise here that will be resolved once onDataReturned is called.
195+
let promise = new Promise((resolve, reject) => {
196+
requestMap[requestId] = {resolve: resolve, reject: reject};
197+
});
198+
199+
UIManager.dispatchViewManagerCommand(
200+
findNodeHandle(this.refs.pdfView),
201+
UIManager.RCTPSPDFKitView.Commands.removeAnnotation,
202+
[requestId, annotation]
203+
);
204+
205+
return promise;
206+
};
207+
182208
/**
183209
* Gets toolbar items currently shown.
184210
*

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.23.10",
3+
"version": "1.23.11",
44
"description": "A React Native module for the PSPDFKit library.",
55
"keywords": [
66
"react native",

samples/Catalog/Catalog.windows.js

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616
TouchableHighlight,
1717
NativeModules,
1818
Button,
19-
Linking
19+
Linking
2020
} from "react-native";
2121
import {StackNavigator} from "react-navigation";
2222
import PSPDFKitView from "react-native-pspdfkit";
@@ -406,7 +406,7 @@ class PdfViewInstantJsonScreen extends Component<{}> {
406406
alert(JSON.stringify(annotations));
407407
});
408408
}}
409-
title="Get annotations"
409+
title="Get Annotations"
410410
/>
411411
</View>
412412
<View style={{marginLeft: 10}}>
@@ -419,7 +419,24 @@ class PdfViewInstantJsonScreen extends Component<{}> {
419419
alert(error);
420420
});
421421
}}
422-
title="Add annotation"
422+
title="Add Annotation"
423+
/>
424+
</View>
425+
<View style={{marginLeft: 10}}>
426+
<Button
427+
onPress={() => {
428+
this.refs.pdfView.getAnnotations(0).then(result => {
429+
if (result.annotations !== undefined && result.annotations.length > 0) {
430+
// Removes the ink annotation if added with Add annotation button rejects if not present
431+
this.refs.pdfView.removeAnnotation(result.annotations[0]).then(() => {
432+
alert("Annotation removal was successful.");
433+
}).catch(error => {
434+
alert(error);
435+
});
436+
}
437+
});
438+
}}
439+
title="Remove Annotation"
423440
/>
424441
</View>
425442
</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.23.10",
3+
"version": "1.23.11",
44
"private": true,
55
"scripts": {
66
"start": "node node_modules/react-native/local-cli/cli.js start"

windows/ReactNativePSPDFKit/ReactNativePSPDFKit/Events/PdfViewDataReturnedEvent.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public PdfViewDataReturnedEvent(int viewId, int requestId, IEnumerable<IAnnotati
3232

3333
var annotations = new JObject
3434
{
35-
{ "annoations",annotationsSerialized}
35+
{ "annotations",annotationsSerialized}
3636
};
3737
_payload.Add("result", annotations);
3838
}

windows/ReactNativePSPDFKit/ReactNativePSPDFKit/PDFViewPage.xaml.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,17 @@ await Pdfview.Document.CreateAnnotationAsync(
159159
);
160160
}
161161

162+
internal async Task RemoveAnnotation(int requestId, string annotationJsonString)
163+
{
164+
await RunOperationAndFireEvent(requestId,
165+
async () =>
166+
{
167+
var annotation = Factory.FromJson(JsonObject.Parse(annotationJsonString));
168+
await Pdfview.Document.DeleteAnnotationAsync(annotation.Id);
169+
}
170+
);
171+
}
172+
162173
internal async Task SetInteractionMode(int requestId, InteractionMode interactionMode)
163174
{
164175
await RunOperationAndFireEvent(requestId,

windows/ReactNativePSPDFKit/ReactNativePSPDFKit/PSPDFKitViewManager.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public class PSPDFKitViewManger : SimpleViewManager<PDFViewPage>
3131
private const int COMMAND_ADD_ANNOTATION = 5;
3232
private const int COMMAND_GET_TOOLBAR_ITEMS = 6;
3333
private const int COMMAND_SET_TOOLBAR_ITEMS = 7;
34+
private const int COMMAND_REMOVE_ANNOTATION = 8;
3435

3536
internal readonly PDFViewPage PdfViewPage = new PDFViewPage();
3637

@@ -80,6 +81,9 @@ public void SetHideNavigationBar(PDFViewPage view, bool hideNavigationBar)
8081
{
8182
"addAnnotation", COMMAND_ADD_ANNOTATION
8283
},
84+
{
85+
"removeAnnotation", COMMAND_REMOVE_ANNOTATION
86+
},
8387
{
8488
"getToolbarItems", COMMAND_GET_TOOLBAR_ITEMS
8589
},
@@ -107,6 +111,9 @@ public override async void ReceiveCommand(PDFViewPage view, int commandId, JArra
107111
case COMMAND_ADD_ANNOTATION:
108112
await PdfViewPage.CreateAnnotation(args[0].Value<int>(), args[1].ToString());
109113
break;
114+
case COMMAND_REMOVE_ANNOTATION:
115+
await PdfViewPage.RemoveAnnotation(args[0].Value<int>(), args[1].ToString());
116+
break;
110117
case COMMAND_GET_TOOLBAR_ITEMS:
111118
PdfViewPage.GetToolbarItems(args[0].Value<int>());
112119
break;

0 commit comments

Comments
 (0)