From 73053dfb84c7db0245668ef11007a947233198bd Mon Sep 17 00:00:00 2001 From: Nick Date: Tue, 21 May 2019 08:23:25 -0600 Subject: [PATCH 1/2] Pass back array of annotations like iOS does. --- .../Events/PdfViewAnnotationChangedEvent.cs | 17 +++++--- .../ReactNativePSPDFKit/PDFViewPage.xaml.cs | 39 +++++++------------ .../PSPDFKitViewManager.cs | 4 -- 3 files changed, 27 insertions(+), 33 deletions(-) diff --git a/windows/ReactNativePSPDFKit/ReactNativePSPDFKit/Events/PdfViewAnnotationChangedEvent.cs b/windows/ReactNativePSPDFKit/ReactNativePSPDFKit/Events/PdfViewAnnotationChangedEvent.cs index 8c2b8f39..5aaedd92 100644 --- a/windows/ReactNativePSPDFKit/ReactNativePSPDFKit/Events/PdfViewAnnotationChangedEvent.cs +++ b/windows/ReactNativePSPDFKit/ReactNativePSPDFKit/Events/PdfViewAnnotationChangedEvent.cs @@ -1,6 +1,7 @@ using Newtonsoft.Json.Linq; using PSPDFKit.Pdf.Annotation; using ReactNative.UIManager.Events; +using System.Collections.Generic; namespace ReactNativePSPDFKit.Events { @@ -15,22 +16,28 @@ class PdfViewAnnotationChangedEvent : Event public const string EVENT_TYPE_REMOVED = "removed"; private readonly string _eventType; - private readonly IAnnotation _annotation; + private readonly IList _annotations; - public PdfViewAnnotationChangedEvent(int viewId, string eventType, IAnnotation annotation) : base(viewId) + public PdfViewAnnotationChangedEvent(int viewId, string eventType, IList annotations) : base(viewId) { - this._eventType = eventType; - this._annotation = annotation; + _eventType = eventType; + _annotations = annotations; } public override string EventName => EVENT_NAME; public override void Dispatch(RCTEventEmitter rctEventEmitter) { + var annotationsJson = new JArray(); + foreach (var annotation in _annotations) + { + annotationsJson.Add(JObject.Parse(annotation.ToJson().Stringify())); + } + var eventData = new JObject { { "change", _eventType }, - { "annotations", JObject.Parse(_annotation.ToJson().Stringify()) } + { "annotations", annotationsJson } }; rctEventEmitter.receiveEvent(ViewTag, EventName, eventData); diff --git a/windows/ReactNativePSPDFKit/ReactNativePSPDFKit/PDFViewPage.xaml.cs b/windows/ReactNativePSPDFKit/ReactNativePSPDFKit/PDFViewPage.xaml.cs index c4e2a77d..72e63e51 100644 --- a/windows/ReactNativePSPDFKit/ReactNativePSPDFKit/PDFViewPage.xaml.cs +++ b/windows/ReactNativePSPDFKit/ReactNativePSPDFKit/PDFViewPage.xaml.cs @@ -216,37 +216,28 @@ private async void PDFView_InitializationCompletedHandlerAsync(PdfView sender, P _pdfViewInitialised = true; } - private void DocumentOnAnnotationsCreated(object sender, IList annotationList) + private void DocumentOnAnnotationsCreated(object sender, IList annotations) { - foreach (var annotation in annotationList) - { - this.GetReactContext().GetNativeModule().EventDispatcher.DispatchEvent( - new PdfViewAnnotationChangedEvent(this.GetTag(), - PdfViewAnnotationChangedEvent.EVENT_TYPE_ADDED, annotation) - ); - } + this.GetReactContext().GetNativeModule().EventDispatcher.DispatchEvent( + new PdfViewAnnotationChangedEvent(this.GetTag(), + PdfViewAnnotationChangedEvent.EVENT_TYPE_ADDED, annotations) + ); } - private void DocumentOnAnnotationsUpdated(object sender, IList annotationList) + private void DocumentOnAnnotationsUpdated(object sender, IList annotations) { - foreach (var annotation in annotationList) - { - this.GetReactContext().GetNativeModule().EventDispatcher.DispatchEvent( - new PdfViewAnnotationChangedEvent(this.GetTag(), - PdfViewAnnotationChangedEvent.EVENT_TYPE_CHANGED, annotation) - ); - } + this.GetReactContext().GetNativeModule().EventDispatcher.DispatchEvent( + new PdfViewAnnotationChangedEvent(this.GetTag(), + PdfViewAnnotationChangedEvent.EVENT_TYPE_CHANGED, annotations) + ); } - private void DocumentOnAnnotationsDeleted(object sender, IList annotationList) + private void DocumentOnAnnotationsDeleted(object sender, IList annotations) { - foreach (var annotation in annotationList) - { - this.GetReactContext().GetNativeModule().EventDispatcher.DispatchEvent( - new PdfViewAnnotationChangedEvent(this.GetTag(), - PdfViewAnnotationChangedEvent.EVENT_TYPE_REMOVED, annotation) - ); - } + this.GetReactContext().GetNativeModule().EventDispatcher.DispatchEvent( + new PdfViewAnnotationChangedEvent(this.GetTag(), + PdfViewAnnotationChangedEvent.EVENT_TYPE_REMOVED, annotations) + ); } } } \ No newline at end of file diff --git a/windows/ReactNativePSPDFKit/ReactNativePSPDFKit/PSPDFKitViewManager.cs b/windows/ReactNativePSPDFKit/ReactNativePSPDFKit/PSPDFKitViewManager.cs index a76ef5e5..0450c446 100644 --- a/windows/ReactNativePSPDFKit/ReactNativePSPDFKit/PSPDFKitViewManager.cs +++ b/windows/ReactNativePSPDFKit/ReactNativePSPDFKit/PSPDFKitViewManager.cs @@ -8,14 +8,10 @@ // using System; -using System.Collections.Generic; -using System.Linq; -using Windows.Data.Json; using ReactNative.UIManager; using ReactNative.UIManager.Annotations; using Windows.Storage; using Newtonsoft.Json.Linq; -using PSPDFKit.Pdf.Annotation; using PSPDFKit.UI; using ReactNativePSPDFKit.Events; From 9eff27fb219caa70c4a30e56db56be90a45d5307 Mon Sep 17 00:00:00 2001 From: Nick Winder Date: Tue, 21 May 2019 13:03:28 -0700 Subject: [PATCH 2/2] Bumped version. --- package-lock.json | 2 +- package.json | 2 +- samples/Catalog/package.json | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 7a4a54d8..96a54e61 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "react-native-pspdfkit", - "version": "1.23.11", + "version": "1.23.12", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 9f93fa2e..eba8f23b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-native-pspdfkit", - "version": "1.23.11", + "version": "1.23.12", "description": "A React Native module for the PSPDFKit library.", "keywords": [ "react native", diff --git a/samples/Catalog/package.json b/samples/Catalog/package.json index 1a312dea..df539738 100644 --- a/samples/Catalog/package.json +++ b/samples/Catalog/package.json @@ -1,6 +1,6 @@ { "name": "Catalog", - "version": "1.23.11", + "version": "1.23.12", "private": true, "scripts": { "start": "node node_modules/react-native/local-cli/cli.js start"