Skip to content

Commit 557898d

Browse files
authored
Align annotations changed with ios (#224)
This PR changes annotation events on UWP to pass back a list of annotations like Android and iOS does.
1 parent 590f30a commit 557898d

File tree

6 files changed

+30
-36
lines changed

6 files changed

+30
-36
lines changed

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

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.11",
3+
"version": "1.23.12",
44
"private": true,
55
"scripts": {
66
"start": "node node_modules/react-native/local-cli/cli.js start"

windows/ReactNativePSPDFKit/ReactNativePSPDFKit/Events/PdfViewAnnotationChangedEvent.cs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using Newtonsoft.Json.Linq;
22
using PSPDFKit.Pdf.Annotation;
33
using ReactNative.UIManager.Events;
4+
using System.Collections.Generic;
45

56
namespace ReactNativePSPDFKit.Events
67
{
@@ -15,22 +16,28 @@ class PdfViewAnnotationChangedEvent : Event
1516
public const string EVENT_TYPE_REMOVED = "removed";
1617

1718
private readonly string _eventType;
18-
private readonly IAnnotation _annotation;
19+
private readonly IList<IAnnotation> _annotations;
1920

20-
public PdfViewAnnotationChangedEvent(int viewId, string eventType, IAnnotation annotation) : base(viewId)
21+
public PdfViewAnnotationChangedEvent(int viewId, string eventType, IList<IAnnotation> annotations) : base(viewId)
2122
{
22-
this._eventType = eventType;
23-
this._annotation = annotation;
23+
_eventType = eventType;
24+
_annotations = annotations;
2425
}
2526

2627
public override string EventName => EVENT_NAME;
2728

2829
public override void Dispatch(RCTEventEmitter rctEventEmitter)
2930
{
31+
var annotationsJson = new JArray();
32+
foreach (var annotation in _annotations)
33+
{
34+
annotationsJson.Add(JObject.Parse(annotation.ToJson().Stringify()));
35+
}
36+
3037
var eventData = new JObject
3138
{
3239
{ "change", _eventType },
33-
{ "annotations", JObject.Parse(_annotation.ToJson().Stringify()) }
40+
{ "annotations", annotationsJson }
3441
};
3542

3643
rctEventEmitter.receiveEvent(ViewTag, EventName, eventData);

windows/ReactNativePSPDFKit/ReactNativePSPDFKit/PDFViewPage.xaml.cs

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -216,37 +216,28 @@ private async void PDFView_InitializationCompletedHandlerAsync(PdfView sender, P
216216
_pdfViewInitialised = true;
217217
}
218218

219-
private void DocumentOnAnnotationsCreated(object sender, IList<IAnnotation> annotationList)
219+
private void DocumentOnAnnotationsCreated(object sender, IList<IAnnotation> annotations)
220220
{
221-
foreach (var annotation in annotationList)
222-
{
223-
this.GetReactContext().GetNativeModule<UIManagerModule>().EventDispatcher.DispatchEvent(
224-
new PdfViewAnnotationChangedEvent(this.GetTag(),
225-
PdfViewAnnotationChangedEvent.EVENT_TYPE_ADDED, annotation)
226-
);
227-
}
221+
this.GetReactContext().GetNativeModule<UIManagerModule>().EventDispatcher.DispatchEvent(
222+
new PdfViewAnnotationChangedEvent(this.GetTag(),
223+
PdfViewAnnotationChangedEvent.EVENT_TYPE_ADDED, annotations)
224+
);
228225
}
229226

230-
private void DocumentOnAnnotationsUpdated(object sender, IList<IAnnotation> annotationList)
227+
private void DocumentOnAnnotationsUpdated(object sender, IList<IAnnotation> annotations)
231228
{
232-
foreach (var annotation in annotationList)
233-
{
234-
this.GetReactContext().GetNativeModule<UIManagerModule>().EventDispatcher.DispatchEvent(
235-
new PdfViewAnnotationChangedEvent(this.GetTag(),
236-
PdfViewAnnotationChangedEvent.EVENT_TYPE_CHANGED, annotation)
237-
);
238-
}
229+
this.GetReactContext().GetNativeModule<UIManagerModule>().EventDispatcher.DispatchEvent(
230+
new PdfViewAnnotationChangedEvent(this.GetTag(),
231+
PdfViewAnnotationChangedEvent.EVENT_TYPE_CHANGED, annotations)
232+
);
239233
}
240234

241-
private void DocumentOnAnnotationsDeleted(object sender, IList<IAnnotation> annotationList)
235+
private void DocumentOnAnnotationsDeleted(object sender, IList<IAnnotation> annotations)
242236
{
243-
foreach (var annotation in annotationList)
244-
{
245-
this.GetReactContext().GetNativeModule<UIManagerModule>().EventDispatcher.DispatchEvent(
246-
new PdfViewAnnotationChangedEvent(this.GetTag(),
247-
PdfViewAnnotationChangedEvent.EVENT_TYPE_REMOVED, annotation)
248-
);
249-
}
237+
this.GetReactContext().GetNativeModule<UIManagerModule>().EventDispatcher.DispatchEvent(
238+
new PdfViewAnnotationChangedEvent(this.GetTag(),
239+
PdfViewAnnotationChangedEvent.EVENT_TYPE_REMOVED, annotations)
240+
);
250241
}
251242
}
252243
}

windows/ReactNativePSPDFKit/ReactNativePSPDFKit/PSPDFKitViewManager.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,10 @@
88
//
99

1010
using System;
11-
using System.Collections.Generic;
12-
using System.Linq;
13-
using Windows.Data.Json;
1411
using ReactNative.UIManager;
1512
using ReactNative.UIManager.Annotations;
1613
using Windows.Storage;
1714
using Newtonsoft.Json.Linq;
18-
using PSPDFKit.Pdf.Annotation;
1915
using PSPDFKit.UI;
2016
using ReactNativePSPDFKit.Events;
2117

0 commit comments

Comments
 (0)