Skip to content

Commit b1aecaa

Browse files
function rename and iOS fix (#151)
* rename 3 functions * update thumbnailViewEditingEnabled and importAnnot * update readme about deprecation
1 parent 7edb28b commit b1aecaa

File tree

10 files changed

+120
-66
lines changed

10 files changed

+120
-66
lines changed

README.md

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -641,12 +641,12 @@ import { DocumentView, Config } from 'react-native-pdftron';
641641
- [deleteAnnotations](#deleteannotations)
642642
- [saveDocument](#savedocument)
643643
- [setFlagForFields](#setFlagForFields)
644-
- [setValueForFields](#setValueForFields)
644+
- [setValuesForFields](#setValuesForFields)
645645
- [importAnnotationCommand](#importannotationcommand)
646646
- [handleBackButton](#handlebackbutton)
647647
- [selectAnnotation](#selectAnnotation)
648-
- [setFlagForAnnotations](#setFlagForAnnotations)
649-
- [setPropertyForAnnotation](#setPropertyForAnnotation)
648+
- [setFlagsForAnnotations](#setFlagsForAnnotations)
649+
- [setPropertiesForAnnotation](#setPropertiesForAnnotation)
650650
- [getPageCropBox](#getPageCropBox)
651651
- [importBookmarkJson](#importBookmarkJson)
652652
- [setCurrentPage](#setCurrentPage)
@@ -774,9 +774,11 @@ Returns a Promise.
774774
this._viewer.setFlagForFields(['First Name', 'Last Name'], Config.FieldFlags.ReadOnly, true);
775775
```
776776
777-
##### setValueForFields
777+
##### setValuesForFields
778778
Set field values on one or more form fields.
779779
780+
Note: the old function `setValueForFields` is deprecated. Please use this one.
781+
780782
Parameters:
781783
782784
Name | Type | Description
@@ -786,7 +788,7 @@ fieldsMap | object | map of field names and values which should be set
786788
Returns a Promise.
787789
788790
```js
789-
this._viewer.setValueForFields({
791+
this._viewer.setValuesForFields({
790792
'textField1': 'Test',
791793
'textField2': 1234,
792794
'checkboxField1': true,
@@ -836,8 +838,10 @@ Return a Promise.
836838
this._viewer.selectAnnotation('annotId1', 1);
837839
```
838840
839-
##### setFlagForAnnotations
840-
To set flag for specified annotations in the current document. The `flagValue` controls whether a flag will be set to or removed from the annotation.
841+
##### setFlagsForAnnotations
842+
To set flags for specified annotations in the current document. The `flagValue` controls whether a flag will be set to or removed from the annotation.
843+
844+
Note: the old function `setFlagForAnnotations` is deprecated. Please use this one.
841845
842846
Parameters:
843847
@@ -849,7 +853,7 @@ Return a Promise.
849853
850854
```js
851855
// Set flag for annotations in the current document.
852-
this._viewer.setFlagForAnnotations([
856+
this._viewer.setFlagsForAnnotations([
853857
{
854858
id: 'annotId1',
855859
pageNumber: 1,
@@ -864,9 +868,11 @@ this._viewer.setFlagForAnnotations([
864868
}
865869
]);
866870
```
867-
##### setPropertyForAnnotation
871+
##### setPropertiesForAnnotation
868872
To set properties for specified annotation in the current document, if it is valid.
869873
874+
Note: the old function `setPropertyForAnnotation` is deprecated. Please use this one.
875+
870876
Parameters:
871877
872878
Name | Type | Description
@@ -889,7 +895,7 @@ Return a promise.
889895
890896
```js
891897
// Set properties for annotation in the current document.
892-
this._viewer.setPropertyForAnnotation('Pdftron', 1, {
898+
this._viewer.setPropertiesForAnnotation('Pdftron', 1, {
893899
rect: {
894900
x1: 1.1, // left
895901
y1: 3, // bottom

android/src/main/java/com/pdftron/reactnative/modules/DocumentViewModule.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -195,12 +195,12 @@ public void run() {
195195
}
196196

197197
@ReactMethod
198-
public void setValueForFields(final int tag, final ReadableMap map, final Promise promise) {
198+
public void setValuesForFields(final int tag, final ReadableMap map, final Promise promise) {
199199
getReactApplicationContext().runOnUiQueueThread(new Runnable() {
200200
@Override
201201
public void run() {
202202
try {
203-
mDocumentViewInstance.setValueForFields(tag, map);
203+
mDocumentViewInstance.setValuesForFields(tag, map);
204204
promise.resolve(null);
205205
} catch (Exception ex) {
206206
promise.reject(ex);
@@ -240,12 +240,12 @@ public void run() {
240240
}
241241

242242
@ReactMethod
243-
public void setFlagForAnnotations(final int tag, final ReadableArray annotationFlaglist, final Promise promise) {
243+
public void setFlagsForAnnotations(final int tag, final ReadableArray annotationFlaglist, final Promise promise) {
244244
getReactApplicationContext().runOnUiQueueThread(new Runnable() {
245245
@Override
246246
public void run() {
247247
try {
248-
mDocumentViewInstance.setFlagForAnnotations(tag, annotationFlaglist);
248+
mDocumentViewInstance.setFlagsForAnnotations(tag, annotationFlaglist);
249249
promise.resolve(null);
250250
} catch (Exception ex) {
251251
promise.reject(ex);
@@ -270,12 +270,12 @@ public void run() {
270270
}
271271

272272
@ReactMethod
273-
public void setPropertyForAnnotation(final int tag, final String annotId, final int pageNumber, final ReadableMap propertyMap, final Promise promise) {
273+
public void setPropertiesForAnnotation(final int tag, final String annotId, final int pageNumber, final ReadableMap propertyMap, final Promise promise) {
274274
getReactApplicationContext().runOnUiQueueThread(new Runnable() {
275275
@Override
276276
public void run() {
277277
try {
278-
mDocumentViewInstance.setPropertyForAnnotation(tag, annotId, pageNumber, propertyMap);
278+
mDocumentViewInstance.setPropertiesForAnnotation(tag, annotId, pageNumber, propertyMap);
279279
promise.resolve(null);
280280
} catch (Exception ex) {
281281
promise.reject(ex);

android/src/main/java/com/pdftron/reactnative/viewmanagers/DocumentViewViewManager.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -346,12 +346,12 @@ public void setFlagForFields(int tag, ReadableArray fields, Integer flag, Boolea
346346
}
347347
}
348348

349-
public void setValueForFields(int tag, ReadableMap map) throws PDFNetException {
349+
public void setValuesForFields(int tag, ReadableMap map) throws PDFNetException {
350350
DocumentView documentView = mDocumentViews.get(tag);
351351
if (documentView != null) {
352-
documentView.setValueForFields(map);
352+
documentView.setValuesForFields(map);
353353
} else {
354-
throw new PDFNetException("", 0L, getName(), "setValueForFields", "Unable to find DocumentView.");
354+
throw new PDFNetException("", 0L, getName(), "setValuesForFields", "Unable to find DocumentView.");
355355
}
356356
}
357357

@@ -373,12 +373,12 @@ public boolean handleBackButton(int tag) throws PDFNetException {
373373
}
374374
}
375375

376-
public void setFlagForAnnotations(int tag, ReadableArray annotationFlagList) throws PDFNetException {
376+
public void setFlagsForAnnotations(int tag, ReadableArray annotationFlagList) throws PDFNetException {
377377
DocumentView documentView = mDocumentViews.get(tag);
378378
if (documentView != null) {
379-
documentView.setFlagForAnnotations(annotationFlagList);
379+
documentView.setFlagsForAnnotations(annotationFlagList);
380380
} else {
381-
throw new PDFNetException("", 0L, getName(), "setFlagForAnnotation", "Unable to find DocumentView.");
381+
throw new PDFNetException("", 0L, getName(), "setFlagsForAnnotation", "Unable to find DocumentView.");
382382
}
383383
}
384384

@@ -391,12 +391,12 @@ public void selectAnnotation(int tag, String annotId, int pageNumber) throws PDF
391391
}
392392
}
393393

394-
public void setPropertyForAnnotation(int tag, String annotId, int pageNumber, ReadableMap propertyMap) throws PDFNetException {
394+
public void setPropertiesForAnnotation(int tag, String annotId, int pageNumber, ReadableMap propertyMap) throws PDFNetException {
395395
DocumentView documentView = mDocumentViews.get(tag);
396396
if (documentView != null) {
397-
documentView.setPropertyForAnnotation(annotId, pageNumber, propertyMap);
397+
documentView.setPropertiesForAnnotation(annotId, pageNumber, propertyMap);
398398
} else {
399-
throw new PDFNetException("", 0L, getName(), "setPropertyForAnnotation", "Unable to find DocumentView.");
399+
throw new PDFNetException("", 0L, getName(), "setPropertiesForAnnotation", "Unable to find DocumentView.");
400400
}
401401
}
402402

android/src/main/java/com/pdftron/reactnative/views/DocumentView.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1613,7 +1613,7 @@ public void deleteAnnotations(ReadableArray annots) throws PDFNetException {
16131613
}
16141614
}
16151615

1616-
public void setValueForFields(ReadableMap readableMap) throws PDFNetException {
1616+
public void setValuesForFields(ReadableMap readableMap) throws PDFNetException {
16171617
PDFViewCtrl pdfViewCtrl = getPdfViewCtrl();
16181618
PDFDoc pdfDoc = pdfViewCtrl.getDoc();
16191619

@@ -1757,7 +1757,7 @@ public boolean handleBackButton() {
17571757
return false;
17581758
}
17591759

1760-
public void setPropertyForAnnotation(String annotId, int pageNumber, ReadableMap propertyMap) throws PDFNetException {
1760+
public void setPropertiesForAnnotation(String annotId, int pageNumber, ReadableMap propertyMap) throws PDFNetException {
17611761
PDFViewCtrl pdfViewCtrl = getPdfViewCtrl();
17621762
ToolManager toolManager = getToolManager();
17631763

@@ -1837,7 +1837,7 @@ public void setPropertyForAnnotation(String annotId, int pageNumber, ReadableMap
18371837
}
18381838
}
18391839

1840-
public void setFlagForAnnotations(ReadableArray annotationFlagList) throws PDFNetException {
1840+
public void setFlagsForAnnotations(ReadableArray annotationFlagList) throws PDFNetException {
18411841
PDFViewCtrl pdfViewCtrl = getPdfViewCtrl();
18421842
ToolManager toolManager = getToolManager();
18431843
int flagCount = annotationFlagList.size();

ios/RNTPTDocumentView.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -278,13 +278,13 @@ static NSString * const PTFormFieldValueKey = @"fieldValue";
278278

279279
- (void)setFlagForFields:(NSArray<NSString *> *)fields setFlag:(PTFieldFlag)flag toValue:(BOOL)value;
280280

281-
- (void)setValueForFields:(NSDictionary<NSString *, id> *)map;
281+
- (void)setValuesForFields:(NSDictionary<NSString *, id> *)map;
282282

283-
- (void)setFlagForAnnotations:(NSArray *)annotationFlagList;
283+
- (void)setFlagsForAnnotations:(NSArray *)annotationFlagList;
284284

285285
- (void)selectAnnotation:(NSString *)annotationId pageNumber:(NSInteger)pageNumber;
286286

287-
- (void)setPropertyForAnnotation:(NSString *)annotationId pageNumber:(NSInteger)pageNumber propertyMap:(NSDictionary *)propertyMap;
287+
- (void)setPropertiesForAnnotation:(NSString *)annotationId pageNumber:(NSInteger)pageNumber propertyMap:(NSDictionary *)propertyMap;
288288

289289
- (NSDictionary<NSString *, NSNumber *> *)getPageCropBox:(NSInteger)pageNumber;
290290

@@ -294,4 +294,8 @@ static NSString * const PTFormFieldValueKey = @"fieldValue";
294294

295295
@end
296296

297+
298+
@interface RNTPTThumbnailsViewController : PTThumbnailsViewController
299+
300+
@end
297301
NS_ASSUME_NONNULL_END

ios/RNTPTDocumentView.m

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,8 @@ - (void)loadDocumentViewController
193193
}
194194
self.documentViewController.delegate = self;
195195

196+
[PTOverrides overrideClass:[PTThumbnailsViewController class] withClass:[RNTPTThumbnailsViewController class]];
197+
196198
self.documentViewController.navigationListsViewController.bookmarkViewController.delegate = self;
197199
[self applyViewerSettings];
198200
}
@@ -768,20 +770,26 @@ - (NSString *)exportAnnotationsWithOptions:(NSDictionary *)options
768770
- (void)importAnnotations:(NSString *)xfdfString
769771
{
770772
PTPDFViewCtrl *pdfViewCtrl = self.pdfViewCtrl;
771-
BOOL shouldUnlock = NO;
772-
@try {
773-
[pdfViewCtrl DocLockRead];
774-
shouldUnlock = YES;
775-
773+
774+
NSError *error;
775+
__block BOOL hasDownloader = false;
776+
777+
[pdfViewCtrl DocLockReadWithBlock:^(PTPDFDoc * _Nullable doc) {
778+
hasDownloader = [[pdfViewCtrl GetDoc] HasDownloader];
779+
} error:&error];
780+
781+
if (hasDownloader || error) {
782+
return;
783+
}
784+
785+
[pdfViewCtrl DocLock:YES withBlock:^(PTPDFDoc * _Nullable doc) {
776786
PTFDFDoc *fdfDoc = [PTFDFDoc CreateFromXFDF:xfdfString];
777-
778787
[[pdfViewCtrl GetDoc] FDFUpdate:fdfDoc];
779788
[pdfViewCtrl Update:YES];
780-
}
781-
@finally {
782-
if (shouldUnlock) {
783-
[pdfViewCtrl DocUnlockRead];
784-
}
789+
} error:&error];
790+
791+
if (error) {
792+
@throw [NSException exceptionWithName:NSGenericException reason:error.localizedFailureReason userInfo:error.userInfo];
785793
}
786794
}
787795

@@ -892,7 +900,7 @@ - (void)saveDocumentWithCompletionHandler:(void (^)(NSString * _Nullable filePat
892900

893901
#pragma mark - Annotation Flag
894902

895-
- (void)setFlagForAnnotations:(NSArray *)annotationFlagList
903+
- (void)setFlagsForAnnotations:(NSArray *)annotationFlagList
896904
{
897905
if (annotationFlagList.count == 0) {
898906
return;
@@ -994,7 +1002,7 @@ - (void)setFlagForFields:(NSArray<NSString *> *)fields setFlag:(PTFieldFlag)flag
9941002
}
9951003
}
9961004

997-
- (void)setValueForFields:(NSDictionary<NSString *, id> *)map
1005+
- (void)setValuesForFields:(NSDictionary<NSString *, id> *)map
9981006
{
9991007
PTPDFViewCtrl *pdfViewCtrl = self.pdfViewCtrl;
10001008
BOOL shouldUnlock = NO;
@@ -1215,6 +1223,7 @@ - (void)applyViewerSettings
12151223

12161224
// Thumbnail editing enabled.
12171225
self.documentViewController.thumbnailsViewController.editingEnabled = self.thumbnailViewEditingEnabled;
1226+
self.documentViewController.thumbnailsViewController.navigationController.toolbarHidden = !self.thumbnailViewEditingEnabled;
12181227

12191228
// Select after creation.
12201229
self.toolManager.selectAnnotationAfterCreation = self.selectAnnotationAfterCreation;
@@ -2130,7 +2139,7 @@ -(void)selectAnnotation:(NSString *)annotationId pageNumber:(NSInteger)pageNumbe
21302139

21312140
#pragma mark - Set Property for Annotation
21322141

2133-
- (void)setPropertyForAnnotation:(NSString *)annotationId pageNumber:(NSInteger)pageNumber propertyMap:(NSDictionary *)propertyMap {
2142+
- (void)setPropertiesForAnnotation:(NSString *)annotationId pageNumber:(NSInteger)pageNumber propertyMap:(NSDictionary *)propertyMap {
21342143

21352144
NSError *error;
21362145

@@ -2271,3 +2280,13 @@ + (NSDictionary *)PT_idAsNSDictionary:(id)value
22712280

22722281
@end
22732282

2283+
#pragma mark - RNTPTThumbnailsViewController
2284+
2285+
@implementation RNTPTThumbnailsViewController
2286+
2287+
-(void) viewWillAppear:(BOOL)animated
2288+
{
2289+
[super viewWillAppear:animated];
2290+
self.navigationController.toolbarHidden = !self.editingEnabled;
2291+
}
2292+
@end

ios/RNTPTDocumentViewManager.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,13 @@
3434

3535
- (void)setFlagForFieldsForDocumentViewTag:(NSNumber *)tag forFields:(NSArray<NSString *> *)fields setFlag:(PTFieldFlag)flag toValue:(BOOL)value;
3636

37-
- (void)setValueForFieldsForDocumentViewTag:(NSNumber *)tag map:(NSDictionary<NSString *, id> *)map;
37+
- (void)setValuesForFieldsForDocumentViewTag:(NSNumber *)tag map:(NSDictionary<NSString *, id> *)map;
3838

39-
- (void)setFlagForAnnotationsForDocumentViewTag:(NSNumber*) tag annotationFlagList:(NSArray *)annotationFlagList;
39+
- (void)setFlagsForAnnotationsForDocumentViewTag:(NSNumber*) tag annotationFlagList:(NSArray *)annotationFlagList;
4040

4141
- (void)selectAnnotationForDocumentViewTag:(NSNumber *)tag annotationId:(NSString *)annotationId pageNumber:(NSInteger)pageNumber;
4242

43-
- (void)setPropertyForAnnotation:(NSNumber *)tag annotationId:(NSString *)annotationId pageNumber:(NSInteger)pageNumber propertyMap:(NSDictionary *)propertyMap;
43+
- (void)setPropertiesForAnnotation:(NSNumber *)tag annotationId:(NSString *)annotationId pageNumber:(NSInteger)pageNumber propertyMap:(NSDictionary *)propertyMap;
4444

4545
- (NSDictionary<NSString *, NSNumber *> *)getPageCropBoxForDocumentViewTag:(NSNumber *)tag pageNumber:(NSInteger)pageNumber;
4646

ios/RNTPTDocumentViewManager.m

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -573,21 +573,21 @@ - (void)setFlagForFieldsForDocumentViewTag:(NSNumber *)tag forFields:(NSArray<NS
573573
}
574574
}
575575

576-
- (void)setValueForFieldsForDocumentViewTag:(NSNumber *)tag map:(NSDictionary<NSString *, id> *)map
576+
- (void)setValuesForFieldsForDocumentViewTag:(NSNumber *)tag map:(NSDictionary<NSString *, id> *)map
577577
{
578578
RNTPTDocumentView *documentView = self.documentViews[tag];
579579
if (documentView) {
580-
[documentView setValueForFields:map];
580+
[documentView setValuesForFields:map];
581581
} else {
582582
@throw [NSException exceptionWithName:NSInvalidArgumentException reason:@"Unable to find DocumentView for tag" userInfo:nil];
583583
}
584584
}
585585

586-
- (void)setFlagForAnnotationsForDocumentViewTag:(NSNumber *)tag annotationFlagList:(NSArray *)annotationFlagList
586+
- (void)setFlagsForAnnotationsForDocumentViewTag:(NSNumber *)tag annotationFlagList:(NSArray *)annotationFlagList
587587
{
588588
RNTPTDocumentView *documentView = self.documentViews[tag];
589589
if (documentView) {
590-
[documentView setFlagForAnnotations:annotationFlagList];
590+
[documentView setFlagsForAnnotations:annotationFlagList];
591591
} else {
592592
@throw [NSException exceptionWithName:NSInvalidArgumentException reason:@"Unable to find DocumentView for tag" userInfo:nil];
593593
}
@@ -603,11 +603,11 @@ - (void)selectAnnotationForDocumentViewTag:(NSNumber *)tag annotationId:(NSStrin
603603
}
604604
}
605605

606-
- (void)setPropertyForAnnotation:(NSNumber *)tag annotationId:(NSString *)annotationId pageNumber:(NSInteger)pageNumber propertyMap:(NSDictionary *)propertyMap
606+
- (void)setPropertiesForAnnotation:(NSNumber *)tag annotationId:(NSString *)annotationId pageNumber:(NSInteger)pageNumber propertyMap:(NSDictionary *)propertyMap
607607
{
608608
RNTPTDocumentView *documentView = self.documentViews[tag];
609609
if (documentView) {
610-
[documentView setPropertyForAnnotation:annotationId pageNumber:pageNumber propertyMap:propertyMap];
610+
[documentView setPropertiesForAnnotation:annotationId pageNumber:pageNumber propertyMap:propertyMap];
611611
} else {
612612
@throw [NSException exceptionWithName:NSInvalidArgumentException reason:@"Unable to find DocumentView for tag" userInfo:nil];
613613
}

0 commit comments

Comments
 (0)