From 11d7003fa431df1bcc05a1dbc77bc0fe65f42786 Mon Sep 17 00:00:00 2001 From: Stefan Kieleithner Date: Thu, 3 Jan 2019 15:39:01 +0100 Subject: [PATCH 1/5] Use uuid instead of name for removing annotation --- .../Converters/RCTConvert+PSPDFAnnotation.m | 10 +++++---- ios/RCTPSPDFKit/RCTPSPDFKitView.h | 2 +- ios/RCTPSPDFKit/RCTPSPDFKitView.m | 22 +++++-------------- ios/RCTPSPDFKit/RCTPSPDFKitViewManager.m | 2 +- 4 files changed, 13 insertions(+), 23 deletions(-) diff --git a/ios/RCTPSPDFKit/Converters/RCTConvert+PSPDFAnnotation.m b/ios/RCTPSPDFKit/Converters/RCTConvert+PSPDFAnnotation.m index e76c6309..e93e8638 100644 --- a/ios/RCTPSPDFKit/Converters/RCTConvert+PSPDFAnnotation.m +++ b/ios/RCTPSPDFKit/Converters/RCTConvert+PSPDFAnnotation.m @@ -14,15 +14,17 @@ @implementation RCTConvert (PSPDFAnnotation) + (NSArray *)instantJSONFromAnnotations:(NSArray *) annotations { NSMutableArray *annotationsJSON = [NSMutableArray new]; for (PSPDFAnnotation *annotation in annotations) { + NSDictionary *uuidDict = @{@"uuid" : [annotation valueForKey:@"uuid"]}; NSData *annotationData = [annotation generateInstantJSONWithError:NULL]; if (annotationData) { - NSDictionary *annotationDictionary = [NSJSONSerialization JSONObjectWithData:annotationData options:kNilOptions error:NULL]; + NSMutableDictionary *annotationDictionary = [[NSJSONSerialization JSONObjectWithData:annotationData options:kNilOptions error:NULL] mutableCopy]; + [annotationDictionary addEntriesFromDictionary:uuidDict]; if (annotationDictionary) { [annotationsJSON addObject:annotationDictionary]; } - } else if (annotation.name) { - // We only generate Instant JSON data for attached annotations. When an annotation is deleted, we only send the annotation name. - [annotationsJSON addObject:@{@"name" : annotation.name}]; + } else { + // We only generate Instant JSON data for attached annotations. When an annotation is deleted, we only set the annotation uuid. + [annotationsJSON addObject:uuidDict]; } } diff --git a/ios/RCTPSPDFKit/RCTPSPDFKitView.h b/ios/RCTPSPDFKit/RCTPSPDFKitView.h index 5847d3dc..d022ed06 100644 --- a/ios/RCTPSPDFKit/RCTPSPDFKitView.h +++ b/ios/RCTPSPDFKit/RCTPSPDFKitView.h @@ -38,7 +38,7 @@ /// Anotations - (NSDictionary *> *)getAnnotations:(PSPDFPageIndex)pageIndex type:(PSPDFAnnotationType)type; - (BOOL)addAnnotation:(id)jsonAnnotation; -- (BOOL)removeAnnotation:(id)jsonAnnotation; +- (BOOL)removeAnnotationWithUUID:(NSString *)annotationUUID; - (NSDictionary *> *)getAllUnsavedAnnotations; - (BOOL)addAnnotations:(NSString *)jsonAnnotations; diff --git a/ios/RCTPSPDFKit/RCTPSPDFKitView.m b/ios/RCTPSPDFKit/RCTPSPDFKitView.m index 58e4c45e..068e2fb8 100644 --- a/ios/RCTPSPDFKit/RCTPSPDFKitView.m +++ b/ios/RCTPSPDFKit/RCTPSPDFKitView.m @@ -205,31 +205,19 @@ - (BOOL)addAnnotation:(id)jsonAnnotation { return success; } -- (BOOL)removeAnnotation:(id)jsonAnnotation { - NSData *data; - if ([jsonAnnotation isKindOfClass:NSString.class]) { - data = [jsonAnnotation dataUsingEncoding:NSUTF8StringEncoding]; - } else if ([jsonAnnotation isKindOfClass:NSDictionary.class]) { - data = [NSJSONSerialization dataWithJSONObject:jsonAnnotation options:0 error:nil]; - } else { - NSLog(@"Invalid JSON Annotation."); - return NO; - } - +- (BOOL)removeAnnotationWithUUID:(NSString *)annotationUUID { PSPDFDocument *document = self.pdfController.document; - PSPDFDocumentProvider *documentProvider = document.documentProviders.firstObject; BOOL success = NO; - if (data) { - PSPDFAnnotation *annotationToRemove = [PSPDFAnnotation annotationFromInstantJSON:data documentProvider:documentProvider error:NULL]; - for (PSPDFAnnotation *annotation in [document annotationsForPageAtIndex:annotationToRemove.pageIndex type:annotationToRemove.type]) { + + NSArray *allAnnotations = [[document allAnnotationsOfType:PSPDFAnnotationTypeAll].allValues valueForKeyPath:@"@unionOfArrays.self"]; + for (PSPDFAnnotation *annotation in allAnnotations) { // Remove the annotation if the name matches. - if ([annotation.name isEqualToString:annotationToRemove.name]) { + if ([[annotation valueForKey:@"uuid"] isEqualToString:annotationUUID]) { success = [document removeAnnotations:@[annotation] options:nil]; break; } } - } if (!success) { NSLog(@"Failed to remove annotation."); diff --git a/ios/RCTPSPDFKit/RCTPSPDFKitViewManager.m b/ios/RCTPSPDFKit/RCTPSPDFKitViewManager.m index a75d0355..0730aeb5 100644 --- a/ios/RCTPSPDFKit/RCTPSPDFKitViewManager.m +++ b/ios/RCTPSPDFKit/RCTPSPDFKitViewManager.m @@ -147,7 +147,7 @@ @implementation RCTPSPDFKitViewManager RCT_EXPORT_METHOD(removeAnnotation:(id)jsonAnnotation reactTag:(nonnull NSNumber *)reactTag resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) { dispatch_async(dispatch_get_main_queue(), ^{ RCTPSPDFKitView *component = (RCTPSPDFKitView *)[self.bridge.uiManager viewForReactTag:reactTag]; - BOOL success = [component removeAnnotation:jsonAnnotation]; + BOOL success = [component removeAnnotationWithUUID:jsonAnnotation[@"uuid"]]; if (success) { resolve(@(success)); } else { From a75487e5bfca59d2810f1dd2a0513d985654c2b1 Mon Sep 17 00:00:00 2001 From: Stefan Kieleithner Date: Tue, 8 Jan 2019 09:13:38 -0500 Subject: [PATCH 2/5] Update ios/RCTPSPDFKit/RCTPSPDFKitView.m Co-Authored-By: radazzouz --- ios/RCTPSPDFKit/RCTPSPDFKitView.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ios/RCTPSPDFKit/RCTPSPDFKitView.m b/ios/RCTPSPDFKit/RCTPSPDFKitView.m index 068e2fb8..c08085b8 100644 --- a/ios/RCTPSPDFKit/RCTPSPDFKitView.m +++ b/ios/RCTPSPDFKit/RCTPSPDFKitView.m @@ -213,7 +213,7 @@ - (BOOL)removeAnnotationWithUUID:(NSString *)annotationUUID { NSArray *allAnnotations = [[document allAnnotationsOfType:PSPDFAnnotationTypeAll].allValues valueForKeyPath:@"@unionOfArrays.self"]; for (PSPDFAnnotation *annotation in allAnnotations) { // Remove the annotation if the name matches. - if ([[annotation valueForKey:@"uuid"] isEqualToString:annotationUUID]) { + if ([annotation.uuid isEqualToString:annotationUUID]) { success = [document removeAnnotations:@[annotation] options:nil]; break; } From ca95f155245581759430e0ec7ec15d1a99f54347 Mon Sep 17 00:00:00 2001 From: Stefan Kieleithner Date: Tue, 8 Jan 2019 09:13:44 -0500 Subject: [PATCH 3/5] Update ios/RCTPSPDFKit/Converters/RCTConvert+PSPDFAnnotation.m Co-Authored-By: radazzouz --- ios/RCTPSPDFKit/Converters/RCTConvert+PSPDFAnnotation.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ios/RCTPSPDFKit/Converters/RCTConvert+PSPDFAnnotation.m b/ios/RCTPSPDFKit/Converters/RCTConvert+PSPDFAnnotation.m index e93e8638..2f9ad854 100644 --- a/ios/RCTPSPDFKit/Converters/RCTConvert+PSPDFAnnotation.m +++ b/ios/RCTPSPDFKit/Converters/RCTConvert+PSPDFAnnotation.m @@ -14,7 +14,7 @@ @implementation RCTConvert (PSPDFAnnotation) + (NSArray *)instantJSONFromAnnotations:(NSArray *) annotations { NSMutableArray *annotationsJSON = [NSMutableArray new]; for (PSPDFAnnotation *annotation in annotations) { - NSDictionary *uuidDict = @{@"uuid" : [annotation valueForKey:@"uuid"]}; + NSDictionary *uuidDict = @{@"uuid" : annotation.uuid}; NSData *annotationData = [annotation generateInstantJSONWithError:NULL]; if (annotationData) { NSMutableDictionary *annotationDictionary = [[NSJSONSerialization JSONObjectWithData:annotationData options:kNilOptions error:NULL] mutableCopy]; From 40ba0560240ea3b71095de59aec7fdb087a14a7b Mon Sep 17 00:00:00 2001 From: RadAzzouz Date: Tue, 15 Jan 2019 08:45:41 -0500 Subject: [PATCH 4/5] Bump version to 1.23.0 --- package-lock.json | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index 4e51cafa..e8fc2088 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "react-native-pspdfkit", - "version": "1.22.0", + "version": "1.23.0", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index a3bb645b..db765504 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-native-pspdfkit", - "version": "1.22.0", + "version": "1.23.0", "description": "A React Native module for the PSPDFKit library.", "keywords": [ "react native", From c2c2339b0a4ee038adcb0cc24fe0f23767e30ee2 Mon Sep 17 00:00:00 2001 From: RadAzzouz Date: Tue, 15 Jan 2019 08:59:54 -0500 Subject: [PATCH 5/5] Update PSPDFKit for iOS required version in the README and cocoapods --- README.md | 2 +- ios/cocoapods.md | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index cac3ca56..f295f44d 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ The [PSPDFKit SDK](https://pspdfkit.com/) is a framework that allows you to view #### Requirements - Xcode 10.1 -- PSPDFKit 8.1 for iOS or later +- PSPDFKit 8.1.3 for iOS or later - react-native >= 0.55.4 #### Getting Started diff --git a/ios/cocoapods.md b/ios/cocoapods.md index 6a6df720..0a45413d 100644 --- a/ios/cocoapods.md +++ b/ios/cocoapods.md @@ -3,8 +3,8 @@ ### CocoaPods integration #### Requirements -- Xcode 10 -- PSPDFKit 8.0 for iOS or later +- Xcode 10.1 +- PSPDFKit 8.1.3 for iOS or later - react-native >= 0.55.4 - CocoaPods >= 1.5.3