File tree 8 files changed +18
-28
lines changed
8 files changed +18
-28
lines changed Original file line number Diff line number Diff line change @@ -25,7 +25,7 @@ The [PSPDFKit SDK](https://pspdfkit.com/) is a framework that allows you to view
25
25
#### Requirements
26
26
27
27
- Xcode 10.1
28
- - PSPDFKit 8.1 for iOS or later
28
+ - PSPDFKit 8.1.3 for iOS or later
29
29
- react-native >= 0.55.4
30
30
31
31
#### Getting Started
Original file line number Diff line number Diff line change @@ -14,15 +14,17 @@ @implementation RCTConvert (PSPDFAnnotation)
14
14
+ (NSArray <NSDictionary *> *)instantJSONFromAnnotations : (NSArray <PSPDFAnnotation *> *) annotations {
15
15
NSMutableArray <NSDictionary *> *annotationsJSON = [NSMutableArray new ];
16
16
for (PSPDFAnnotation *annotation in annotations) {
17
+ NSDictionary <NSString *, NSString *> *uuidDict = @{@" uuid" : annotation.uuid };
17
18
NSData *annotationData = [annotation generateInstantJSONWithError: NULL ];
18
19
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];
20
22
if (annotationDictionary) {
21
23
[annotationsJSON addObject: annotationDictionary];
22
24
}
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 ];
26
28
}
27
29
}
28
30
Original file line number Diff line number Diff line change 38
38
// / Anotations
39
39
- (NSDictionary <NSString *, NSArray<NSDictionary *> *> *)getAnnotations : (PSPDFPageIndex)pageIndex type : (PSPDFAnnotationType)type ;
40
40
- (BOOL )addAnnotation : (id )jsonAnnotation ;
41
- - (BOOL )removeAnnotation : ( id ) jsonAnnotation ;
41
+ - (BOOL )removeAnnotationWithUUID : ( NSString *) annotationUUID ;
42
42
- (NSDictionary <NSString *, NSArray<NSDictionary *> *> *)getAllUnsavedAnnotations ;
43
43
- (BOOL )addAnnotations : (NSString *)jsonAnnotations ;
44
44
Original file line number Diff line number Diff line change @@ -205,31 +205,19 @@ - (BOOL)addAnnotation:(id)jsonAnnotation {
205
205
return success;
206
206
}
207
207
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 {
219
209
PSPDFDocument *document = self.pdfController .document ;
220
- PSPDFDocumentProvider *documentProvider = document.documentProviders .firstObject ;
221
210
222
211
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 ) {
226
215
// Remove the annotation if the name matches.
227
- if ([annotation.name isEqualToString: annotationToRemove.name ]) {
216
+ if ([annotation.uuid isEqualToString: annotationUUID ]) {
228
217
success = [document removeAnnotations: @[annotation] options: nil ];
229
218
break ;
230
219
}
231
220
}
232
- }
233
221
234
222
if (!success) {
235
223
NSLog (@" Failed to remove annotation." );
Original file line number Diff line number Diff line change @@ -147,7 +147,7 @@ @implementation RCTPSPDFKitViewManager
147
147
RCT_EXPORT_METHOD (removeAnnotation:(id )jsonAnnotation reactTag:(nonnull NSNumber *)reactTag resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
148
148
dispatch_async (dispatch_get_main_queue (), ^{
149
149
RCTPSPDFKitView *component = (RCTPSPDFKitView *)[self .bridge.uiManager viewForReactTag: reactTag];
150
- BOOL success = [component removeAnnotation : jsonAnnotation];
150
+ BOOL success = [component removeAnnotationWithUUID : jsonAnnotation[ @" uuid " ] ];
151
151
if (success) {
152
152
resolve (@(success));
153
153
} else {
Original file line number Diff line number Diff line change 3
3
### CocoaPods integration
4
4
5
5
#### 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
8
8
- react-native >= 0.55.4
9
9
- CocoaPods >= 1.5.3
10
10
Original file line number Diff line number Diff line change 1
1
{
2
2
"name" : " react-native-pspdfkit" ,
3
- "version" : " 1.22 .0" ,
3
+ "version" : " 1.23 .0" ,
4
4
"description" : " A React Native module for the PSPDFKit library." ,
5
5
"keywords" : [
6
6
" react native" ,
You can’t perform that action at this time.
0 commit comments