@amafil/react-native-pdf-toolkit 1.1.0 → 1.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +57 -0
- package/android/build/.transforms/2892d280277a194daf04e3af971b529e/results.bin +1 -0
- package/android/build/.transforms/2892d280277a194daf04e3af971b529e/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/com/facebook/react/viewmanagers/RNPDFPdfViewManagerDelegate.dex +0 -0
- package/android/build/.transforms/2892d280277a194daf04e3af971b529e/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/com/facebook/react/viewmanagers/RNPDFPdfViewManagerInterface.dex +0 -0
- package/android/build/.transforms/2892d280277a194daf04e3af971b529e/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/org/wonday/pdf/BuildConfig.dex +0 -0
- package/android/build/.transforms/2892d280277a194daf04e3af971b529e/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/org/wonday/pdf/PdfManager.dex +0 -0
- package/android/build/.transforms/2892d280277a194daf04e3af971b529e/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/org/wonday/pdf/PdfView$1.dex +0 -0
- package/android/build/.transforms/2892d280277a194daf04e3af971b529e/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/org/wonday/pdf/PdfView$2.dex +0 -0
- package/android/build/.transforms/2892d280277a194daf04e3af971b529e/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/org/wonday/pdf/PdfView$3.dex +0 -0
- package/android/build/.transforms/2892d280277a194daf04e3af971b529e/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/org/wonday/pdf/PdfView$AnnotationOverlayView$1.dex +0 -0
- package/android/build/.transforms/2892d280277a194daf04e3af971b529e/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/org/wonday/pdf/PdfView$AnnotationOverlayView$AnnotationHit.dex +0 -0
- package/android/build/.transforms/2892d280277a194daf04e3af971b529e/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/org/wonday/pdf/PdfView$AnnotationOverlayView$AnnotationSelectionHit.dex +0 -0
- package/android/build/.transforms/2892d280277a194daf04e3af971b529e/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/org/wonday/pdf/PdfView$AnnotationOverlayView.dex +0 -0
- package/android/build/.transforms/2892d280277a194daf04e3af971b529e/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/org/wonday/pdf/PdfView.dex +0 -0
- package/android/build/.transforms/2892d280277a194daf04e3af971b529e/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/org/wonday/pdf/RNPDFPackage.dex +0 -0
- package/android/build/.transforms/2892d280277a194daf04e3af971b529e/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/org/wonday/pdf/events/TopChangeEvent.dex +0 -0
- package/android/build/.transforms/2892d280277a194daf04e3af971b529e/transformed/bundleLibRuntimeToDirDebug/desugar_graph.bin +0 -0
- package/android/build/.transforms/e40f3b884607647e8beb6dabe8165962/results.bin +1 -0
- package/android/build/.transforms/e40f3b884607647e8beb6dabe8165962/transformed/classes/classes_dex/classes.dex +0 -0
- package/android/build/generated/source/buildConfig/debug/org/wonday/pdf/BuildConfig.java +1 -1
- package/android/build/generated/source/codegen/java/com/facebook/react/viewmanagers/RNPDFPdfViewManagerDelegate.java +31 -0
- package/android/build/generated/source/codegen/java/com/facebook/react/viewmanagers/RNPDFPdfViewManagerInterface.java +10 -0
- package/android/build/generated/source/codegen/jni/react/renderer/components/rnpdf/Props.cpp +35 -0
- package/android/build/generated/source/codegen/jni/react/renderer/components/rnpdf/Props.h +10 -0
- package/android/build/generated/source/codegen/schema.json +1 -1
- package/android/build/intermediates/compile_library_classes_jar/debug/bundleLibCompileToJarDebug/classes.jar +0 -0
- package/android/build/intermediates/incremental/debug/packageDebugResources/compile-file-map.properties +1 -1
- package/android/build/intermediates/incremental/debug/packageDebugResources/merger.xml +1 -1
- package/android/build/intermediates/javac/debug/compileDebugJavaWithJavac/classes/com/facebook/react/viewmanagers/RNPDFPdfViewManagerDelegate.class +0 -0
- package/android/build/intermediates/javac/debug/compileDebugJavaWithJavac/classes/com/facebook/react/viewmanagers/RNPDFPdfViewManagerInterface.class +0 -0
- package/android/build/intermediates/javac/debug/compileDebugJavaWithJavac/classes/org/wonday/pdf/PdfManager.class +0 -0
- package/android/build/intermediates/javac/debug/compileDebugJavaWithJavac/classes/org/wonday/pdf/PdfView$1.class +0 -0
- package/android/build/intermediates/javac/debug/compileDebugJavaWithJavac/classes/org/wonday/pdf/PdfView$2.class +0 -0
- package/android/build/intermediates/javac/debug/compileDebugJavaWithJavac/classes/org/wonday/pdf/PdfView$3.class +0 -0
- package/android/build/intermediates/javac/debug/compileDebugJavaWithJavac/classes/org/wonday/pdf/PdfView$AnnotationOverlayView$1.class +0 -0
- package/android/build/intermediates/javac/debug/compileDebugJavaWithJavac/classes/org/wonday/pdf/PdfView$AnnotationOverlayView$AnnotationHit.class +0 -0
- package/android/build/intermediates/javac/debug/compileDebugJavaWithJavac/classes/org/wonday/pdf/PdfView$AnnotationOverlayView$AnnotationSelectionHit.class +0 -0
- package/android/build/intermediates/javac/debug/compileDebugJavaWithJavac/classes/org/wonday/pdf/PdfView$AnnotationOverlayView.class +0 -0
- package/android/build/intermediates/javac/debug/compileDebugJavaWithJavac/classes/org/wonday/pdf/PdfView.class +0 -0
- package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/com/facebook/react/viewmanagers/RNPDFPdfViewManagerDelegate.class +0 -0
- package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/com/facebook/react/viewmanagers/RNPDFPdfViewManagerInterface.class +0 -0
- package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/org/wonday/pdf/PdfManager.class +0 -0
- package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/org/wonday/pdf/PdfView$1.class +0 -0
- package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/org/wonday/pdf/PdfView$2.class +0 -0
- package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/org/wonday/pdf/PdfView$3.class +0 -0
- package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/org/wonday/pdf/PdfView$AnnotationOverlayView$1.class +0 -0
- package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/org/wonday/pdf/PdfView$AnnotationOverlayView$AnnotationHit.class +0 -0
- package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/org/wonday/pdf/PdfView$AnnotationOverlayView$AnnotationSelectionHit.class +0 -0
- package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/org/wonday/pdf/PdfView$AnnotationOverlayView.class +0 -0
- package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/org/wonday/pdf/PdfView.class +0 -0
- package/android/build/intermediates/runtime_library_classes_jar/debug/bundleLibRuntimeToJarDebug/classes.jar +0 -0
- package/android/build/outputs/logs/manifest-merger-debug-report.txt +9 -18
- package/android/build/tmp/compileDebugJavaWithJavac/previous-compilation-data.bin +0 -0
- package/android/src/main/java/org/wonday/pdf/PdfManager.java +24 -0
- package/android/src/main/java/org/wonday/pdf/PdfView.java +80 -49
- package/android/src/paper/java/com/facebook/react/viewmanagers/RNPDFPdfViewManagerDelegate.java +12 -0
- package/android/src/paper/java/com/facebook/react/viewmanagers/RNPDFPdfViewManagerInterface.java +4 -0
- package/annotationDocumentUtils.js +74 -0
- package/fabric/RNPDFPdfNativeComponent.js +10 -3
- package/index.d.ts +36 -2
- package/index.js +42 -21
- package/index.js.flow +6 -2
- package/ios/RNPDFPdf/RNPDFPdfView.h +4 -0
- package/ios/RNPDFPdf/RNPDFPdfView.mm +107 -61
- package/ios/RNPDFPdf/RNPDFPdfViewManager.mm +22 -0
- package/package.json +6 -5
- package/android/build/generated/source/codegen/jni/react/renderer/components/rnpdf/rnpdfJSI-generated.cpp +0 -17
|
@@ -63,9 +63,12 @@ const float MIN_SCALE = 1.0f;
|
|
|
63
63
|
@property(nonatomic, assign) BOOL annotationEditable;
|
|
64
64
|
@property(nonatomic, copy) NSString *annotationTool;
|
|
65
65
|
@property(nonatomic, copy) NSString *annotationIdMode;
|
|
66
|
+
@property(nonatomic, copy) NSString *annotationInkColor;
|
|
67
|
+
@property(nonatomic, assign) CGFloat annotationInkThickness;
|
|
66
68
|
|
|
67
69
|
- (void)replaceAnnotationsJSONString:(NSString *)json editable:(BOOL)editable idMode:(NSString *)idMode;
|
|
68
70
|
- (void)setAnnotationMode:(BOOL)annotationMode tool:(NSString *)tool editable:(BOOL)editable idMode:(NSString *)idMode;
|
|
71
|
+
- (void)setInkDefaultsColor:(NSString *)color thickness:(CGFloat)thickness;
|
|
69
72
|
- (void)beginInkAtViewPoint:(CGPoint)viewPoint page:(PDFPage *)page;
|
|
70
73
|
- (void)appendInkPointAtViewPoint:(CGPoint)viewPoint page:(PDFPage *)page;
|
|
71
74
|
- (void)endInk;
|
|
@@ -77,6 +80,8 @@ const float MIN_SCALE = 1.0f;
|
|
|
77
80
|
- (void)selectAnnotation:(NSDictionary *)annotation;
|
|
78
81
|
- (void)clearSelection;
|
|
79
82
|
- (void)deleteAnnotation:(NSDictionary *)annotation;
|
|
83
|
+
- (void)deleteSelectedAnnotation;
|
|
84
|
+
- (void)deleteAllAnnotations;
|
|
80
85
|
- (void)beginSelectionInteractionAtPoint:(CGPoint)point hit:(NSDictionary *)hit;
|
|
81
86
|
- (void)updateSelectionInteractionAtPoint:(CGPoint)point;
|
|
82
87
|
- (void)endSelectionInteraction;
|
|
@@ -209,6 +214,14 @@ using namespace facebook::react;
|
|
|
209
214
|
_annotationIdMode = RCTNSStringFromStringNilIfEmpty(newProps.annotationIdMode);
|
|
210
215
|
[updatedPropNames addObject:@"annotationIdMode"];
|
|
211
216
|
}
|
|
217
|
+
if (_annotationInkColor != RCTNSStringFromStringNilIfEmpty(newProps.annotationInkColor)) {
|
|
218
|
+
_annotationInkColor = RCTNSStringFromStringNilIfEmpty(newProps.annotationInkColor);
|
|
219
|
+
[updatedPropNames addObject:@"annotationInkColor"];
|
|
220
|
+
}
|
|
221
|
+
if (_annotationInkThickness != newProps.annotationInkThickness) {
|
|
222
|
+
_annotationInkThickness = newProps.annotationInkThickness;
|
|
223
|
+
[updatedPropNames addObject:@"annotationInkThickness"];
|
|
224
|
+
}
|
|
212
225
|
if (_fitPolicy != newProps.fitPolicy) {
|
|
213
226
|
_fitPolicy = newProps.fitPolicy;
|
|
214
227
|
[updatedPropNames addObject:@"fitPolicy"];
|
|
@@ -245,6 +258,7 @@ using namespace facebook::react;
|
|
|
245
258
|
if (_annotationOverlay) {
|
|
246
259
|
[_annotationOverlay replaceAnnotationsJSONString:_annotations editable:_annotationEditable idMode:_annotationIdMode];
|
|
247
260
|
[_annotationOverlay setAnnotationMode:_annotationMode tool:_annotationTool editable:_annotationEditable idMode:_annotationIdMode];
|
|
261
|
+
[_annotationOverlay setInkDefaultsColor:_annotationInkColor thickness:_annotationInkThickness];
|
|
248
262
|
_annotationOverlay.pdfView = _pdfView;
|
|
249
263
|
_annotationOverlay.pdfDocument = _pdfDocument;
|
|
250
264
|
}
|
|
@@ -353,6 +367,8 @@ using namespace facebook::react;
|
|
|
353
367
|
_showsHorizontalScrollIndicator = YES;
|
|
354
368
|
_showsVerticalScrollIndicator = YES;
|
|
355
369
|
_scrollEnabled = YES;
|
|
370
|
+
_annotationInkColor = @"#111111";
|
|
371
|
+
_annotationInkThickness = 2.0f;
|
|
356
372
|
_enableTextSelection = YES;
|
|
357
373
|
_selectedText = nil;
|
|
358
374
|
_currentPDFSelection = nil;
|
|
@@ -383,6 +399,7 @@ using namespace facebook::react;
|
|
|
383
399
|
_annotationOverlay.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
|
|
384
400
|
_annotationOverlay.backgroundColor = UIColor.clearColor;
|
|
385
401
|
_annotationOverlay.userInteractionEnabled = YES;
|
|
402
|
+
[_annotationOverlay setInkDefaultsColor:_annotationInkColor thickness:_annotationInkThickness];
|
|
386
403
|
[self addSubview:_annotationOverlay];
|
|
387
404
|
[self bringSubviewToFront:_annotationOverlay];
|
|
388
405
|
|
|
@@ -672,6 +689,14 @@ using namespace facebook::react;
|
|
|
672
689
|
}
|
|
673
690
|
}
|
|
674
691
|
|
|
692
|
+
if (_annotationOverlay) {
|
|
693
|
+
[_annotationOverlay replaceAnnotationsJSONString:_annotations editable:_annotationEditable idMode:_annotationIdMode];
|
|
694
|
+
[_annotationOverlay setAnnotationMode:_annotationMode tool:_annotationTool editable:_annotationEditable idMode:_annotationIdMode];
|
|
695
|
+
[_annotationOverlay setInkDefaultsColor:_annotationInkColor thickness:_annotationInkThickness];
|
|
696
|
+
_annotationOverlay.pdfView = _pdfView;
|
|
697
|
+
_annotationOverlay.pdfDocument = _pdfDocument;
|
|
698
|
+
}
|
|
699
|
+
|
|
675
700
|
_pdfView.backgroundColor = [UIColor clearColor];
|
|
676
701
|
[_pdfView layoutDocumentView];
|
|
677
702
|
[self setNeedsDisplay];
|
|
@@ -960,12 +985,7 @@ using namespace facebook::react;
|
|
|
960
985
|
NSDictionary *hit = [_annotationOverlay annotationSelectionHitAtPoint:point includeHandles:YES];
|
|
961
986
|
if (hit) {
|
|
962
987
|
NSDictionary *annotation = hit[@"annotation"];
|
|
963
|
-
|
|
964
|
-
if ([hitPart isEqualToString:@"delete"]) {
|
|
965
|
-
[_annotationOverlay deleteAnnotation:annotation];
|
|
966
|
-
} else {
|
|
967
|
-
[_annotationOverlay selectAnnotation:annotation];
|
|
968
|
-
}
|
|
988
|
+
[_annotationOverlay selectAnnotation:annotation];
|
|
969
989
|
|
|
970
990
|
return;
|
|
971
991
|
}
|
|
@@ -1032,14 +1052,7 @@ using namespace facebook::react;
|
|
|
1032
1052
|
return;
|
|
1033
1053
|
}
|
|
1034
1054
|
|
|
1035
|
-
|
|
1036
|
-
NSString *hitPart = hit[@"hitPart"];
|
|
1037
|
-
if ([hitPart isEqualToString:@"delete"]) {
|
|
1038
|
-
[_annotationOverlay deleteAnnotation:annotation];
|
|
1039
|
-
return;
|
|
1040
|
-
}
|
|
1041
|
-
|
|
1042
|
-
[_annotationOverlay selectAnnotation:annotation];
|
|
1055
|
+
[_annotationOverlay selectAnnotation:hit[@"annotation"]];
|
|
1043
1056
|
[_annotationOverlay beginSelectionInteractionAtPoint:point hit:hit];
|
|
1044
1057
|
} else if (sender.state == UIGestureRecognizerStateChanged) {
|
|
1045
1058
|
[_annotationOverlay updateSelectionInteractionAtPoint:point];
|
|
@@ -1052,19 +1065,19 @@ using namespace facebook::react;
|
|
|
1052
1065
|
if (sender.state == UIGestureRecognizerStateBegan) {
|
|
1053
1066
|
if ([_annotationTool isEqualToString:@"ink"]) {
|
|
1054
1067
|
[_annotationOverlay beginInkAtViewPoint:point page:pdfPage];
|
|
1055
|
-
} else if ([
|
|
1068
|
+
} else if ([_annotationTool isEqualToString:@"highlight"]) {
|
|
1056
1069
|
[_annotationOverlay beginMarkupAtViewPoint:point page:pdfPage type:_annotationTool];
|
|
1057
1070
|
}
|
|
1058
1071
|
} else if (sender.state == UIGestureRecognizerStateChanged) {
|
|
1059
1072
|
if ([_annotationTool isEqualToString:@"ink"]) {
|
|
1060
1073
|
[_annotationOverlay appendInkPointAtViewPoint:point page:pdfPage];
|
|
1061
|
-
} else if ([
|
|
1074
|
+
} else if ([_annotationTool isEqualToString:@"highlight"]) {
|
|
1062
1075
|
[_annotationOverlay updateMarkupAtViewPoint:point page:pdfPage];
|
|
1063
1076
|
}
|
|
1064
1077
|
} else if (sender.state == UIGestureRecognizerStateEnded || sender.state == UIGestureRecognizerStateCancelled || sender.state == UIGestureRecognizerStateFailed) {
|
|
1065
1078
|
if ([_annotationTool isEqualToString:@"ink"]) {
|
|
1066
1079
|
[_annotationOverlay endInk];
|
|
1067
|
-
} else if ([
|
|
1080
|
+
} else if ([_annotationTool isEqualToString:@"highlight"]) {
|
|
1068
1081
|
[_annotationOverlay endMarkup];
|
|
1069
1082
|
}
|
|
1070
1083
|
}
|
|
@@ -1082,6 +1095,22 @@ using namespace facebook::react;
|
|
|
1082
1095
|
[self notifyOnChangeWithMessage:@"annotationSaveError|Annotation overlay unavailable"];
|
|
1083
1096
|
}
|
|
1084
1097
|
|
|
1098
|
+
- (void)deleteSelectedAnnotation
|
|
1099
|
+
{
|
|
1100
|
+
if (_annotationOverlay) {
|
|
1101
|
+
[_annotationOverlay commitTextEditingIfNeeded];
|
|
1102
|
+
[_annotationOverlay deleteSelectedAnnotation];
|
|
1103
|
+
}
|
|
1104
|
+
}
|
|
1105
|
+
|
|
1106
|
+
- (void)deleteAllAnnotations
|
|
1107
|
+
{
|
|
1108
|
+
if (_annotationOverlay) {
|
|
1109
|
+
[_annotationOverlay commitTextEditingIfNeeded];
|
|
1110
|
+
[_annotationOverlay deleteAllAnnotations];
|
|
1111
|
+
}
|
|
1112
|
+
}
|
|
1113
|
+
|
|
1085
1114
|
/**
|
|
1086
1115
|
* Bind tap
|
|
1087
1116
|
*
|
|
@@ -1158,7 +1187,7 @@ using namespace facebook::react;
|
|
|
1158
1187
|
return [_annotationOverlay annotationSelectionHitAtPoint:point includeHandles:YES] != nil;
|
|
1159
1188
|
}
|
|
1160
1189
|
|
|
1161
|
-
return [@[@"ink", @"highlight"
|
|
1190
|
+
return [@[@"ink", @"highlight"] containsObject:_annotationTool];
|
|
1162
1191
|
}
|
|
1163
1192
|
|
|
1164
1193
|
return !_singlePage;
|
|
@@ -1407,6 +1436,8 @@ static NSString *RNPDFGenerateAnnotationId(void)
|
|
|
1407
1436
|
_annotationEditable = YES;
|
|
1408
1437
|
_annotationTool = @"select";
|
|
1409
1438
|
_annotationIdMode = @"auto";
|
|
1439
|
+
_annotationInkColor = @"#111111";
|
|
1440
|
+
_annotationInkThickness = 2.0f;
|
|
1410
1441
|
self.backgroundColor = UIColor.clearColor;
|
|
1411
1442
|
self.opaque = NO;
|
|
1412
1443
|
}
|
|
@@ -1441,7 +1472,7 @@ static NSString *RNPDFGenerateAnnotationId(void)
|
|
|
1441
1472
|
{
|
|
1442
1473
|
_annotationMode = annotationMode;
|
|
1443
1474
|
_annotationEditable = editable;
|
|
1444
|
-
_annotationTool = tool ?: @"select";
|
|
1475
|
+
_annotationTool = [self normalizedAnnotationType:(tool ?: @"select")];
|
|
1445
1476
|
_annotationIdMode = idMode ?: @"auto";
|
|
1446
1477
|
|
|
1447
1478
|
if (!annotationMode) {
|
|
@@ -1449,6 +1480,27 @@ static NSString *RNPDFGenerateAnnotationId(void)
|
|
|
1449
1480
|
}
|
|
1450
1481
|
}
|
|
1451
1482
|
|
|
1483
|
+
- (void)setInkDefaultsColor:(NSString *)color thickness:(CGFloat)thickness
|
|
1484
|
+
{
|
|
1485
|
+
_annotationInkColor = color.length > 0 ? color : @"#111111";
|
|
1486
|
+
_annotationInkThickness = thickness > 0 ? thickness : 2.0f;
|
|
1487
|
+
}
|
|
1488
|
+
|
|
1489
|
+
- (NSString *)normalizedAnnotationType:(NSString *)type
|
|
1490
|
+
{
|
|
1491
|
+
if ([type isEqualToString:@"underline"] || [type isEqualToString:@"strikeout"]) {
|
|
1492
|
+
return @"highlight";
|
|
1493
|
+
}
|
|
1494
|
+
|
|
1495
|
+
return type;
|
|
1496
|
+
}
|
|
1497
|
+
|
|
1498
|
+
- (BOOL)annotationSupportsResize:(NSDictionary *)annotation
|
|
1499
|
+
{
|
|
1500
|
+
NSString *type = [self normalizedAnnotationType:annotation[@"type"]];
|
|
1501
|
+
return [type isEqualToString:@"text"] || [type isEqualToString:@"highlight"];
|
|
1502
|
+
}
|
|
1503
|
+
|
|
1452
1504
|
- (NSArray *)parseAnnotationsFromJSONString:(NSString *)json
|
|
1453
1505
|
{
|
|
1454
1506
|
if (![json isKindOfClass:[NSString class]] || json.length == 0) {
|
|
@@ -1487,6 +1539,10 @@ static NSString *RNPDFGenerateAnnotationId(void)
|
|
|
1487
1539
|
}
|
|
1488
1540
|
|
|
1489
1541
|
NSMutableDictionary *annotation = [item mutableCopy];
|
|
1542
|
+
NSString *type = [self normalizedAnnotationType:annotation[@"type"]];
|
|
1543
|
+
if (type.length > 0) {
|
|
1544
|
+
annotation[@"type"] = type;
|
|
1545
|
+
}
|
|
1490
1546
|
if (!annotation[@"id"]) {
|
|
1491
1547
|
annotation[@"id"] = RNPDFGenerateAnnotationId();
|
|
1492
1548
|
}
|
|
@@ -1727,12 +1783,6 @@ static NSString *RNPDFGenerateAnnotationId(void)
|
|
|
1727
1783
|
return nil;
|
|
1728
1784
|
}
|
|
1729
1785
|
|
|
1730
|
-
- (CGRect)deleteHandleRectForRect:(CGRect)rect
|
|
1731
|
-
{
|
|
1732
|
-
CGFloat size = MAX(16.0f, MIN(rect.size.width, rect.size.height) * 0.18f);
|
|
1733
|
-
return CGRectMake(CGRectGetMaxX(rect) - size, CGRectGetMinY(rect) - size, size, size);
|
|
1734
|
-
}
|
|
1735
|
-
|
|
1736
1786
|
- (CGRect)resizeHandleRectForRect:(CGRect)rect
|
|
1737
1787
|
{
|
|
1738
1788
|
CGFloat size = MAX(16.0f, MIN(rect.size.width, rect.size.height) * 0.18f);
|
|
@@ -1768,12 +1818,8 @@ static NSString *RNPDFGenerateAnnotationId(void)
|
|
|
1768
1818
|
}
|
|
1769
1819
|
|
|
1770
1820
|
NSString *hitPart = @"body";
|
|
1771
|
-
if (includeHandles && [_selectedAnnotationId isEqualToString:annotation[@"id"]]) {
|
|
1772
|
-
|
|
1773
|
-
hitPart = @"delete";
|
|
1774
|
-
} else if (CGRectContainsPoint([self resizeHandleRectForRect:rect], point)) {
|
|
1775
|
-
hitPart = @"resize";
|
|
1776
|
-
}
|
|
1821
|
+
if (includeHandles && [_selectedAnnotationId isEqualToString:annotation[@"id"]] && [self annotationSupportsResize:annotation] && CGRectContainsPoint([self resizeHandleRectForRect:rect], point)) {
|
|
1822
|
+
hitPart = @"resize";
|
|
1777
1823
|
}
|
|
1778
1824
|
|
|
1779
1825
|
return @{@"annotation": annotation,
|
|
@@ -1832,6 +1878,23 @@ static NSString *RNPDFGenerateAnnotationId(void)
|
|
|
1832
1878
|
[self refreshDisplay];
|
|
1833
1879
|
}
|
|
1834
1880
|
|
|
1881
|
+
- (void)deleteSelectedAnnotation
|
|
1882
|
+
{
|
|
1883
|
+
NSDictionary *annotation = [self selectedAnnotation];
|
|
1884
|
+
if (annotation) {
|
|
1885
|
+
[self deleteAnnotation:annotation];
|
|
1886
|
+
}
|
|
1887
|
+
}
|
|
1888
|
+
|
|
1889
|
+
- (void)deleteAllAnnotations
|
|
1890
|
+
{
|
|
1891
|
+
[self commitTextEditingIfNeeded];
|
|
1892
|
+
[_draftAnnotations removeAllObjects];
|
|
1893
|
+
_selectedAnnotationId = nil;
|
|
1894
|
+
[self endSelectionInteraction];
|
|
1895
|
+
[self refreshDisplay];
|
|
1896
|
+
}
|
|
1897
|
+
|
|
1835
1898
|
- (void)beginSelectionInteractionAtPoint:(CGPoint)point hit:(NSDictionary *)hit
|
|
1836
1899
|
{
|
|
1837
1900
|
NSDictionary *annotation = hit[@"annotation"];
|
|
@@ -1961,15 +2024,12 @@ static NSString *RNPDFGenerateAnnotationId(void)
|
|
|
1961
2024
|
[outlineColor setStroke];
|
|
1962
2025
|
[outlinePath stroke];
|
|
1963
2026
|
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
[[UIColor colorWithRed:0.13 green:0.27 blue:0.67 alpha:0.95] setFill];
|
|
1971
|
-
UIBezierPath *resizePath = [UIBezierPath bezierPathWithRoundedRect:resizeHandle cornerRadius:2.0f];
|
|
1972
|
-
[resizePath fill];
|
|
2027
|
+
if ([self annotationSupportsResize:annotation]) {
|
|
2028
|
+
CGRect resizeHandle = [self resizeHandleRectForRect:rect];
|
|
2029
|
+
[[UIColor colorWithRed:0.13 green:0.27 blue:0.67 alpha:0.95] setFill];
|
|
2030
|
+
UIBezierPath *resizePath = [UIBezierPath bezierPathWithRoundedRect:resizeHandle cornerRadius:2.0f];
|
|
2031
|
+
[resizePath fill];
|
|
2032
|
+
}
|
|
1973
2033
|
}
|
|
1974
2034
|
|
|
1975
2035
|
- (NSDictionary *)normalizedBoundsForViewRect:(CGRect)viewRect page:(PDFPage *)page
|
|
@@ -1999,21 +2059,16 @@ static NSString *RNPDFGenerateAnnotationId(void)
|
|
|
1999
2059
|
|
|
2000
2060
|
- (UIColor *)colorForAnnotationType:(NSString *)type style:(NSDictionary *)style
|
|
2001
2061
|
{
|
|
2062
|
+
NSString *normalizedType = [self normalizedAnnotationType:type];
|
|
2002
2063
|
NSString *colorString = [style isKindOfClass:[NSDictionary class]] ? style[@"color"] : nil;
|
|
2003
2064
|
if (colorString) {
|
|
2004
2065
|
return RNPDFColorFromHexString(colorString, UIColor.blackColor);
|
|
2005
2066
|
}
|
|
2006
2067
|
|
|
2007
|
-
if ([
|
|
2068
|
+
if ([normalizedType isEqualToString:@"highlight"]) {
|
|
2008
2069
|
return [UIColor colorWithRed:1.0 green:0.93 blue:0.2 alpha:0.35];
|
|
2009
2070
|
}
|
|
2010
|
-
if ([
|
|
2011
|
-
return [UIColor colorWithRed:0.2 green:0.45 blue:1.0 alpha:0.5];
|
|
2012
|
-
}
|
|
2013
|
-
if ([type isEqualToString:@"strikeout"]) {
|
|
2014
|
-
return [UIColor colorWithRed:1.0 green:0.2 blue:0.2 alpha:0.45];
|
|
2015
|
-
}
|
|
2016
|
-
if ([type isEqualToString:@"text"]) {
|
|
2071
|
+
if ([normalizedType isEqualToString:@"text"]) {
|
|
2017
2072
|
return [UIColor colorWithRed:0.13 green:0.27 blue:0.67 alpha:1.0];
|
|
2018
2073
|
}
|
|
2019
2074
|
|
|
@@ -2074,7 +2129,7 @@ static NSString *RNPDFGenerateAnnotationId(void)
|
|
|
2074
2129
|
}
|
|
2075
2130
|
|
|
2076
2131
|
PDFPage *page = [_pdfDocument pageAtIndex:pageIndex];
|
|
2077
|
-
NSString *type = annotation[@"type"];
|
|
2132
|
+
NSString *type = [self normalizedAnnotationType:annotation[@"type"]];
|
|
2078
2133
|
if ([type isEqualToString:@"ink"]) {
|
|
2079
2134
|
NSArray *points = annotation[@"points"];
|
|
2080
2135
|
if (points.count < 2) {
|
|
@@ -2127,7 +2182,7 @@ static NSString *RNPDFGenerateAnnotationId(void)
|
|
|
2127
2182
|
NSParagraphStyleAttributeName: paragraphStyle,
|
|
2128
2183
|
};
|
|
2129
2184
|
[text drawInRect:CGRectInset(viewRect, 6.0f, 4.0f) withAttributes:attributes];
|
|
2130
|
-
} else if ([type isEqualToString:@"highlight"]
|
|
2185
|
+
} else if ([type isEqualToString:@"highlight"]) {
|
|
2131
2186
|
NSDictionary *bounds = annotation[@"bounds"];
|
|
2132
2187
|
CGRect viewRect = [self viewRectForNormalizedBounds:bounds page:page];
|
|
2133
2188
|
if (CGRectIsEmpty(viewRect)) {
|
|
@@ -2137,15 +2192,6 @@ static NSString *RNPDFGenerateAnnotationId(void)
|
|
|
2137
2192
|
UIColor *fillColor = [self colorForAnnotationType:type style:annotation[@"style"]];
|
|
2138
2193
|
CGContextSetFillColorWithColor(context, fillColor.CGColor);
|
|
2139
2194
|
CGContextFillRect(context, viewRect);
|
|
2140
|
-
|
|
2141
|
-
if ([type isEqualToString:@"underline"] || [type isEqualToString:@"strikeout"]) {
|
|
2142
|
-
CGContextSetStrokeColorWithColor(context, fillColor.CGColor);
|
|
2143
|
-
CGContextSetLineWidth(context, MAX(1.0f, viewRect.size.height * 0.15f));
|
|
2144
|
-
CGFloat y = [type isEqualToString:@"underline"] ? CGRectGetMaxY(viewRect) - 2.0f : CGRectGetMidY(viewRect);
|
|
2145
|
-
CGContextMoveToPoint(context, CGRectGetMinX(viewRect), y);
|
|
2146
|
-
CGContextAddLineToPoint(context, CGRectGetMaxX(viewRect), y);
|
|
2147
|
-
CGContextStrokePath(context);
|
|
2148
|
-
}
|
|
2149
2195
|
}
|
|
2150
2196
|
}
|
|
2151
2197
|
|
|
@@ -2163,7 +2209,7 @@ static NSString *RNPDFGenerateAnnotationId(void)
|
|
|
2163
2209
|
@"page": @([_pdfDocument indexForPage:page] + 1),
|
|
2164
2210
|
@"type": @"ink",
|
|
2165
2211
|
@"points": [NSMutableArray array],
|
|
2166
|
-
@"style": @{@"color": @"#111111", @"thickness": @(2.0f)}
|
|
2212
|
+
@"style": @{@"color": _annotationInkColor ?: @"#111111", @"thickness": @(_annotationInkThickness > 0 ? _annotationInkThickness : 2.0f)}
|
|
2167
2213
|
} mutableCopy];
|
|
2168
2214
|
|
|
2169
2215
|
[_draftAnnotations addObject:annotation];
|
|
@@ -2206,7 +2252,7 @@ static NSString *RNPDFGenerateAnnotationId(void)
|
|
|
2206
2252
|
NSMutableDictionary *annotation = [@{
|
|
2207
2253
|
@"id": [self nextLocalAnnotationId],
|
|
2208
2254
|
@"page": @([_pdfDocument indexForPage:page] + 1),
|
|
2209
|
-
@"type":
|
|
2255
|
+
@"type": @"highlight",
|
|
2210
2256
|
@"bounds": @{@"x": @(normalizedPoint.x), @"y": @(normalizedPoint.y), @"width": @0, @"height": @0},
|
|
2211
2257
|
@"style": @{}
|
|
2212
2258
|
} mutableCopy];
|
|
@@ -51,6 +51,8 @@ RCT_EXPORT_VIEW_PROPERTY(annotationMode, BOOL);
|
|
|
51
51
|
RCT_EXPORT_VIEW_PROPERTY(annotationTool, NSString);
|
|
52
52
|
RCT_EXPORT_VIEW_PROPERTY(annotationEditable, BOOL);
|
|
53
53
|
RCT_EXPORT_VIEW_PROPERTY(annotationIdMode, NSString);
|
|
54
|
+
RCT_EXPORT_VIEW_PROPERTY(annotationInkColor, NSString);
|
|
55
|
+
RCT_EXPORT_VIEW_PROPERTY(annotationInkThickness, float);
|
|
54
56
|
RCT_EXPORT_VIEW_PROPERTY(fitPolicy, int);
|
|
55
57
|
RCT_EXPORT_VIEW_PROPERTY(spacing, int);
|
|
56
58
|
RCT_EXPORT_VIEW_PROPERTY(password, NSString);
|
|
@@ -91,6 +93,26 @@ RCT_EXPORT_METHOD(saveAnnotations:(nonnull NSNumber *)reactTag)
|
|
|
91
93
|
}];
|
|
92
94
|
}
|
|
93
95
|
|
|
96
|
+
RCT_EXPORT_METHOD(deleteSelectedAnnotation:(nonnull NSNumber *)reactTag)
|
|
97
|
+
{
|
|
98
|
+
[self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, UIView *> *viewRegistry) {
|
|
99
|
+
RNPDFPdfView *view = (RNPDFPdfView *)viewRegistry[reactTag];
|
|
100
|
+
if ([view isKindOfClass:[RNPDFPdfView class]]) {
|
|
101
|
+
[view deleteSelectedAnnotation];
|
|
102
|
+
}
|
|
103
|
+
}];
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
RCT_EXPORT_METHOD(deleteAllAnnotations:(nonnull NSNumber *)reactTag)
|
|
107
|
+
{
|
|
108
|
+
[self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, UIView *> *viewRegistry) {
|
|
109
|
+
RNPDFPdfView *view = (RNPDFPdfView *)viewRegistry[reactTag];
|
|
110
|
+
if ([view isKindOfClass:[RNPDFPdfView class]]) {
|
|
111
|
+
[view deleteAllAnnotations];
|
|
112
|
+
}
|
|
113
|
+
}];
|
|
114
|
+
}
|
|
115
|
+
|
|
94
116
|
RCT_EXPORT_METHOD(supportPDFKit:(RCTResponseSenderBlock)callback)
|
|
95
117
|
{
|
|
96
118
|
if([[[UIDevice currentDevice] systemVersion] compare:@"11.0" options:NSNumericSearch] == NSOrderedDescending
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@amafil/react-native-pdf-toolkit",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.2",
|
|
4
4
|
"summary": "A react native PDF view component",
|
|
5
5
|
"description": "A react native PDF view component, support ios and android platform",
|
|
6
6
|
"main": "index.js",
|
|
@@ -28,13 +28,13 @@
|
|
|
28
28
|
"url": "https://github.com/amafil/react-native-pdf/issues"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
+
"@babel/runtime": "^7.20.1",
|
|
31
32
|
"crypto-js": "4.2.0",
|
|
32
|
-
"deprecated-react-native-prop-types": "^2.3.0"
|
|
33
|
+
"deprecated-react-native-prop-types": "^2.3.0",
|
|
34
|
+
"prop-types": "^15.7.2"
|
|
33
35
|
},
|
|
34
36
|
"devDependencies": {
|
|
35
|
-
"@babel/core": "^7.20.2"
|
|
36
|
-
"@babel/runtime": "^7.20.1",
|
|
37
|
-
"prop-types": "^15.7.2"
|
|
37
|
+
"@babel/core": "^7.20.2"
|
|
38
38
|
},
|
|
39
39
|
"peerDependencies": {
|
|
40
40
|
"react": "*",
|
|
@@ -49,6 +49,7 @@
|
|
|
49
49
|
"index.d.ts",
|
|
50
50
|
"index.js",
|
|
51
51
|
"index.js.flow",
|
|
52
|
+
"annotationDocumentUtils.js",
|
|
52
53
|
"PdfManager.js",
|
|
53
54
|
"PdfPageView.js",
|
|
54
55
|
"PdfView.js",
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
|
|
3
|
-
*
|
|
4
|
-
* Do not edit this file as changes may cause incorrect behavior and will be lost
|
|
5
|
-
* once the code is regenerated.
|
|
6
|
-
*
|
|
7
|
-
* @generated by codegen project: GenerateModuleCpp.js
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
#include "rnpdfJSI.h"
|
|
11
|
-
|
|
12
|
-
namespace facebook::react {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
} // namespace facebook::react
|