Skip to content

Commit

Permalink
[iOS] Match Android implementation of importAnnotations (#682)
Browse files Browse the repository at this point in the history
* Add replace parameter to importAnnotations function on iOS

* Update documentation

* Updating package version

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
JamieDass and github-actions[bot] authored Mar 5, 2024
1 parent 16504cf commit 73af623
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 10 deletions.
2 changes: 1 addition & 1 deletion API.md
Original file line number Diff line number Diff line change
Expand Up @@ -2580,7 +2580,7 @@ Parameters:
Name | Type | Description
--- | --- | ---
xfdf | string | annotation string in XFDF format for import
replace | boolean | whether to replace existing form and annotation data with those imported from the XFDF string (Android only)
replace | boolean | whether to replace existing form and annotation data with those imported from the XFDF string

Returns a Promise.
Promise Parameters:
Expand Down
2 changes: 1 addition & 1 deletion ios/RNTPTDocumentView.h
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,7 @@ static NSString * const PTSignaturesManager_signatureDirectory = @"PTSignaturesM

- (nullable NSString *)exportAnnotationsWithOptions:(NSDictionary *)options;

- (nullable NSArray<NSDictionary *> *)importAnnotations:(NSString *)xfdfString;
- (nullable NSArray<NSDictionary *> *)importAnnotations:(NSString *)xfdfString replace:(BOOL)replace;

- (void)flattenAnnotations:(BOOL)formsOnly;

Expand Down
24 changes: 18 additions & 6 deletions ios/RNTPTDocumentView.m
Original file line number Diff line number Diff line change
Expand Up @@ -1353,7 +1353,7 @@ - (NSString *)exportAnnotationsWithOptions:(NSDictionary *)options
return nil;
}

- (nullable NSArray<NSDictionary *> *)importAnnotations:(NSString *)xfdfString
- (nullable NSArray<NSDictionary *> *)importAnnotations:(NSString *)xfdfString replace:(BOOL)replace
{
PTDocumentBaseViewController *documentViewController = self.currentDocumentViewController;
PTPDFViewCtrl *pdfViewCtrl = documentViewController.pdfViewCtrl;
Expand All @@ -1369,12 +1369,24 @@ - (NSString *)exportAnnotationsWithOptions:(NSDictionary *)options
return nil;
}

PTAnnotationManager * const annotationManager = documentViewController.toolManager.annotationManager;
if (self.collaborationManager != nil) {
[self.collaborationManager importAnnotationsWithXFDFString:xfdfString];
return [self getAnnotationFromXFDF:xfdfString];
}

const BOOL updateSuccess = [annotationManager updateAnnotationsWithXFDFString:xfdfString
error:&error];
if (!updateSuccess || error) {
@throw [NSException exceptionWithName:NSGenericException reason:error.localizedFailureReason userInfo:error.userInfo];
[pdfViewCtrl DocLock:YES withBlock:^(PTPDFDoc * _Nullable doc) {
PTFDFDoc *fdfDoc = [PTFDFDoc CreateFromXFDF:xfdfString];
if (replace) {
[doc FDFUpdate:fdfDoc];
} else {
[doc FDFMerge:fdfDoc];
}
[pdfViewCtrl Update:YES];
} error:&error];

if (error) {
NSLog(@"Error: There was an error while trying to import annotations. %@", error.localizedDescription);
return nil;
}

return [self getAnnotationFromXFDF:xfdfString];
Expand Down
2 changes: 1 addition & 1 deletion ios/RNTPTDocumentViewManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -1130,7 +1130,7 @@ - (void)importAnnotationCommandForDocumentViewTag:(NSNumber *)tag xfdfCommand:(N
{
RNTPTDocumentView *documentView = self.documentViews[tag];
if (documentView) {
return [documentView importAnnotations:xfdfString];
return [documentView importAnnotations:xfdfString replace:replace];
} else {
@throw [NSException exceptionWithName:NSInvalidArgumentException reason:@"Unable to find DocumentView for tag" userInfo:nil];
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "react-native-pdftron",
"title": "React Native Pdftron",
"version": "3.0.3-36",
"version": "3.0.3-37",
"description": "React Native Pdftron",
"main": "./lib/index.js",
"typings": "index.ts",
Expand Down

0 comments on commit 73af623

Please sign in to comment.