Skip to content

Commit 0b39ad6

Browse files
authored
Merge pull request #156 from PSPDFKit/use-uuids-for-removal
Use the uuid property to remove an annotation
2 parents e8aea9c + c2c2339 commit 0b39ad6

8 files changed

+18
-28
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ The [PSPDFKit SDK](https://pspdfkit.com/) is a framework that allows you to view
2525
#### Requirements
2626

2727
- Xcode 10.1
28-
- PSPDFKit 8.1 for iOS or later
28+
- PSPDFKit 8.1.3 for iOS or later
2929
- react-native >= 0.55.4
3030

3131
#### Getting Started

ios/RCTPSPDFKit/Converters/RCTConvert+PSPDFAnnotation.m

+6-4
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,17 @@ @implementation RCTConvert (PSPDFAnnotation)
1414
+ (NSArray <NSDictionary *> *)instantJSONFromAnnotations:(NSArray <PSPDFAnnotation *> *) annotations {
1515
NSMutableArray <NSDictionary *> *annotationsJSON = [NSMutableArray new];
1616
for (PSPDFAnnotation *annotation in annotations) {
17+
NSDictionary <NSString *, NSString *> *uuidDict = @{@"uuid" : annotation.uuid};
1718
NSData *annotationData = [annotation generateInstantJSONWithError:NULL];
1819
if (annotationData) {
19-
NSDictionary *annotationDictionary = [NSJSONSerialization JSONObjectWithData:annotationData options:kNilOptions error:NULL];
20+
NSMutableDictionary *annotationDictionary = [[NSJSONSerialization JSONObjectWithData:annotationData options:kNilOptions error:NULL] mutableCopy];
21+
[annotationDictionary addEntriesFromDictionary:uuidDict];
2022
if (annotationDictionary) {
2123
[annotationsJSON addObject:annotationDictionary];
2224
}
23-
} else if (annotation.name) {
24-
// We only generate Instant JSON data for attached annotations. When an annotation is deleted, we only send the annotation name.
25-
[annotationsJSON addObject:@{@"name" : annotation.name}];
25+
} else {
26+
// We only generate Instant JSON data for attached annotations. When an annotation is deleted, we only set the annotation uuid.
27+
[annotationsJSON addObject:uuidDict];
2628
}
2729
}
2830

ios/RCTPSPDFKit/RCTPSPDFKitView.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
/// Anotations
3939
- (NSDictionary<NSString *, NSArray<NSDictionary *> *> *)getAnnotations:(PSPDFPageIndex)pageIndex type:(PSPDFAnnotationType)type;
4040
- (BOOL)addAnnotation:(id)jsonAnnotation;
41-
- (BOOL)removeAnnotation:(id)jsonAnnotation;
41+
- (BOOL)removeAnnotationWithUUID:(NSString *)annotationUUID;
4242
- (NSDictionary<NSString *, NSArray<NSDictionary *> *> *)getAllUnsavedAnnotations;
4343
- (BOOL)addAnnotations:(NSString *)jsonAnnotations;
4444

ios/RCTPSPDFKit/RCTPSPDFKitView.m

+5-17
Original file line numberDiff line numberDiff line change
@@ -205,31 +205,19 @@ - (BOOL)addAnnotation:(id)jsonAnnotation {
205205
return success;
206206
}
207207

208-
- (BOOL)removeAnnotation:(id)jsonAnnotation {
209-
NSData *data;
210-
if ([jsonAnnotation isKindOfClass:NSString.class]) {
211-
data = [jsonAnnotation dataUsingEncoding:NSUTF8StringEncoding];
212-
} else if ([jsonAnnotation isKindOfClass:NSDictionary.class]) {
213-
data = [NSJSONSerialization dataWithJSONObject:jsonAnnotation options:0 error:nil];
214-
} else {
215-
NSLog(@"Invalid JSON Annotation.");
216-
return NO;
217-
}
218-
208+
- (BOOL)removeAnnotationWithUUID:(NSString *)annotationUUID {
219209
PSPDFDocument *document = self.pdfController.document;
220-
PSPDFDocumentProvider *documentProvider = document.documentProviders.firstObject;
221210

222211
BOOL success = NO;
223-
if (data) {
224-
PSPDFAnnotation *annotationToRemove = [PSPDFAnnotation annotationFromInstantJSON:data documentProvider:documentProvider error:NULL];
225-
for (PSPDFAnnotation *annotation in [document annotationsForPageAtIndex:annotationToRemove.pageIndex type:annotationToRemove.type]) {
212+
213+
NSArray<PSPDFAnnotation *> *allAnnotations = [[document allAnnotationsOfType:PSPDFAnnotationTypeAll].allValues valueForKeyPath:@"@unionOfArrays.self"];
214+
for (PSPDFAnnotation *annotation in allAnnotations) {
226215
// Remove the annotation if the name matches.
227-
if ([annotation.name isEqualToString:annotationToRemove.name]) {
216+
if ([annotation.uuid isEqualToString:annotationUUID]) {
228217
success = [document removeAnnotations:@[annotation] options:nil];
229218
break;
230219
}
231220
}
232-
}
233221

234222
if (!success) {
235223
NSLog(@"Failed to remove annotation.");

ios/RCTPSPDFKit/RCTPSPDFKitViewManager.m

+1-1
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ @implementation RCTPSPDFKitViewManager
147147
RCT_EXPORT_METHOD(removeAnnotation:(id)jsonAnnotation reactTag:(nonnull NSNumber *)reactTag resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
148148
dispatch_async(dispatch_get_main_queue(), ^{
149149
RCTPSPDFKitView *component = (RCTPSPDFKitView *)[self.bridge.uiManager viewForReactTag:reactTag];
150-
BOOL success = [component removeAnnotation:jsonAnnotation];
150+
BOOL success = [component removeAnnotationWithUUID:jsonAnnotation[@"uuid"]];
151151
if (success) {
152152
resolve(@(success));
153153
} else {

ios/cocoapods.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
### CocoaPods integration
44

55
#### Requirements
6-
- Xcode 10
7-
- PSPDFKit 8.0 for iOS or later
6+
- Xcode 10.1
7+
- PSPDFKit 8.1.3 for iOS or later
88
- react-native >= 0.55.4
99
- CocoaPods >= 1.5.3
1010

package-lock.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-pspdfkit",
3-
"version": "1.22.0",
3+
"version": "1.23.0",
44
"description": "A React Native module for the PSPDFKit library.",
55
"keywords": [
66
"react native",

0 commit comments

Comments
 (0)