@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.
Files changed (67) hide show
  1. package/README.md +57 -0
  2. package/android/build/.transforms/2892d280277a194daf04e3af971b529e/results.bin +1 -0
  3. package/android/build/.transforms/2892d280277a194daf04e3af971b529e/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/com/facebook/react/viewmanagers/RNPDFPdfViewManagerDelegate.dex +0 -0
  4. package/android/build/.transforms/2892d280277a194daf04e3af971b529e/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/com/facebook/react/viewmanagers/RNPDFPdfViewManagerInterface.dex +0 -0
  5. package/android/build/.transforms/2892d280277a194daf04e3af971b529e/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/org/wonday/pdf/BuildConfig.dex +0 -0
  6. package/android/build/.transforms/2892d280277a194daf04e3af971b529e/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/org/wonday/pdf/PdfManager.dex +0 -0
  7. package/android/build/.transforms/2892d280277a194daf04e3af971b529e/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/org/wonday/pdf/PdfView$1.dex +0 -0
  8. package/android/build/.transforms/2892d280277a194daf04e3af971b529e/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/org/wonday/pdf/PdfView$2.dex +0 -0
  9. package/android/build/.transforms/2892d280277a194daf04e3af971b529e/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/org/wonday/pdf/PdfView$3.dex +0 -0
  10. package/android/build/.transforms/2892d280277a194daf04e3af971b529e/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/org/wonday/pdf/PdfView$AnnotationOverlayView$1.dex +0 -0
  11. package/android/build/.transforms/2892d280277a194daf04e3af971b529e/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/org/wonday/pdf/PdfView$AnnotationOverlayView$AnnotationHit.dex +0 -0
  12. package/android/build/.transforms/2892d280277a194daf04e3af971b529e/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/org/wonday/pdf/PdfView$AnnotationOverlayView$AnnotationSelectionHit.dex +0 -0
  13. package/android/build/.transforms/2892d280277a194daf04e3af971b529e/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/org/wonday/pdf/PdfView$AnnotationOverlayView.dex +0 -0
  14. package/android/build/.transforms/2892d280277a194daf04e3af971b529e/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/org/wonday/pdf/PdfView.dex +0 -0
  15. package/android/build/.transforms/2892d280277a194daf04e3af971b529e/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/org/wonday/pdf/RNPDFPackage.dex +0 -0
  16. package/android/build/.transforms/2892d280277a194daf04e3af971b529e/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/org/wonday/pdf/events/TopChangeEvent.dex +0 -0
  17. package/android/build/.transforms/2892d280277a194daf04e3af971b529e/transformed/bundleLibRuntimeToDirDebug/desugar_graph.bin +0 -0
  18. package/android/build/.transforms/e40f3b884607647e8beb6dabe8165962/results.bin +1 -0
  19. package/android/build/.transforms/e40f3b884607647e8beb6dabe8165962/transformed/classes/classes_dex/classes.dex +0 -0
  20. package/android/build/generated/source/buildConfig/debug/org/wonday/pdf/BuildConfig.java +1 -1
  21. package/android/build/generated/source/codegen/java/com/facebook/react/viewmanagers/RNPDFPdfViewManagerDelegate.java +31 -0
  22. package/android/build/generated/source/codegen/java/com/facebook/react/viewmanagers/RNPDFPdfViewManagerInterface.java +10 -0
  23. package/android/build/generated/source/codegen/jni/react/renderer/components/rnpdf/Props.cpp +35 -0
  24. package/android/build/generated/source/codegen/jni/react/renderer/components/rnpdf/Props.h +10 -0
  25. package/android/build/generated/source/codegen/schema.json +1 -1
  26. package/android/build/intermediates/compile_library_classes_jar/debug/bundleLibCompileToJarDebug/classes.jar +0 -0
  27. package/android/build/intermediates/incremental/debug/packageDebugResources/compile-file-map.properties +1 -1
  28. package/android/build/intermediates/incremental/debug/packageDebugResources/merger.xml +1 -1
  29. package/android/build/intermediates/javac/debug/compileDebugJavaWithJavac/classes/com/facebook/react/viewmanagers/RNPDFPdfViewManagerDelegate.class +0 -0
  30. package/android/build/intermediates/javac/debug/compileDebugJavaWithJavac/classes/com/facebook/react/viewmanagers/RNPDFPdfViewManagerInterface.class +0 -0
  31. package/android/build/intermediates/javac/debug/compileDebugJavaWithJavac/classes/org/wonday/pdf/PdfManager.class +0 -0
  32. package/android/build/intermediates/javac/debug/compileDebugJavaWithJavac/classes/org/wonday/pdf/PdfView$1.class +0 -0
  33. package/android/build/intermediates/javac/debug/compileDebugJavaWithJavac/classes/org/wonday/pdf/PdfView$2.class +0 -0
  34. package/android/build/intermediates/javac/debug/compileDebugJavaWithJavac/classes/org/wonday/pdf/PdfView$3.class +0 -0
  35. package/android/build/intermediates/javac/debug/compileDebugJavaWithJavac/classes/org/wonday/pdf/PdfView$AnnotationOverlayView$1.class +0 -0
  36. package/android/build/intermediates/javac/debug/compileDebugJavaWithJavac/classes/org/wonday/pdf/PdfView$AnnotationOverlayView$AnnotationHit.class +0 -0
  37. package/android/build/intermediates/javac/debug/compileDebugJavaWithJavac/classes/org/wonday/pdf/PdfView$AnnotationOverlayView$AnnotationSelectionHit.class +0 -0
  38. package/android/build/intermediates/javac/debug/compileDebugJavaWithJavac/classes/org/wonday/pdf/PdfView$AnnotationOverlayView.class +0 -0
  39. package/android/build/intermediates/javac/debug/compileDebugJavaWithJavac/classes/org/wonday/pdf/PdfView.class +0 -0
  40. package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/com/facebook/react/viewmanagers/RNPDFPdfViewManagerDelegate.class +0 -0
  41. package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/com/facebook/react/viewmanagers/RNPDFPdfViewManagerInterface.class +0 -0
  42. package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/org/wonday/pdf/PdfManager.class +0 -0
  43. package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/org/wonday/pdf/PdfView$1.class +0 -0
  44. package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/org/wonday/pdf/PdfView$2.class +0 -0
  45. package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/org/wonday/pdf/PdfView$3.class +0 -0
  46. package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/org/wonday/pdf/PdfView$AnnotationOverlayView$1.class +0 -0
  47. package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/org/wonday/pdf/PdfView$AnnotationOverlayView$AnnotationHit.class +0 -0
  48. package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/org/wonday/pdf/PdfView$AnnotationOverlayView$AnnotationSelectionHit.class +0 -0
  49. package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/org/wonday/pdf/PdfView$AnnotationOverlayView.class +0 -0
  50. package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/org/wonday/pdf/PdfView.class +0 -0
  51. package/android/build/intermediates/runtime_library_classes_jar/debug/bundleLibRuntimeToJarDebug/classes.jar +0 -0
  52. package/android/build/outputs/logs/manifest-merger-debug-report.txt +9 -18
  53. package/android/build/tmp/compileDebugJavaWithJavac/previous-compilation-data.bin +0 -0
  54. package/android/src/main/java/org/wonday/pdf/PdfManager.java +24 -0
  55. package/android/src/main/java/org/wonday/pdf/PdfView.java +80 -49
  56. package/android/src/paper/java/com/facebook/react/viewmanagers/RNPDFPdfViewManagerDelegate.java +12 -0
  57. package/android/src/paper/java/com/facebook/react/viewmanagers/RNPDFPdfViewManagerInterface.java +4 -0
  58. package/annotationDocumentUtils.js +74 -0
  59. package/fabric/RNPDFPdfNativeComponent.js +10 -3
  60. package/index.d.ts +36 -2
  61. package/index.js +42 -21
  62. package/index.js.flow +6 -2
  63. package/ios/RNPDFPdf/RNPDFPdfView.h +4 -0
  64. package/ios/RNPDFPdf/RNPDFPdfView.mm +107 -61
  65. package/ios/RNPDFPdf/RNPDFPdfViewManager.mm +22 -0
  66. package/package.json +6 -5
  67. package/android/build/generated/source/codegen/jni/react/renderer/components/rnpdf/rnpdfJSI-generated.cpp +0 -17
@@ -97,6 +97,8 @@ public class PdfView extends PDFView implements OnPageChangeListener,OnLoadCompl
97
97
  private String annotationTool = "select";
98
98
  private boolean annotationEditable = true;
99
99
  private String annotationIdMode = "auto";
100
+ private String annotationInkColor = "#111111";
101
+ private float annotationInkThickness = 2f;
100
102
  private AnnotationOverlayView annotationOverlayView;
101
103
 
102
104
  private boolean enablePaging = false;
@@ -494,6 +496,16 @@ public class PdfView extends PDFView implements OnPageChangeListener,OnLoadCompl
494
496
  updateAnnotationOverlayConfig();
495
497
  }
496
498
 
499
+ public void setAnnotationInkColor(String annotationInkColor) {
500
+ this.annotationInkColor = TextUtils.isEmpty(annotationInkColor) ? "#111111" : annotationInkColor;
501
+ updateAnnotationOverlayConfig();
502
+ }
503
+
504
+ public void setAnnotationInkThickness(float annotationInkThickness) {
505
+ this.annotationInkThickness = annotationInkThickness > 0f ? annotationInkThickness : 2f;
506
+ updateAnnotationOverlayConfig();
507
+ }
508
+
497
509
  public void setPath(String path) {
498
510
  this.path = path;
499
511
  }
@@ -594,7 +606,9 @@ public class PdfView extends PDFView implements OnPageChangeListener,OnLoadCompl
594
606
  this.annotationTool,
595
607
  this.annotationEditable,
596
608
  this.annotationIdMode,
597
- isAnnotationEditingSupported()
609
+ isAnnotationEditingSupported(),
610
+ this.annotationInkColor,
611
+ this.annotationInkThickness
598
612
  );
599
613
  }
600
614
  }
@@ -622,6 +636,8 @@ public class PdfView extends PDFView implements OnPageChangeListener,OnLoadCompl
622
636
  private boolean editable = true;
623
637
  private String idMode = "auto";
624
638
  private boolean supported = true;
639
+ private String inkColor = "#111111";
640
+ private float inkThickness = 2f;
625
641
 
626
642
  AnnotationOverlayView(Context context) {
627
643
  super(context);
@@ -631,12 +647,14 @@ public class PdfView extends PDFView implements OnPageChangeListener,OnLoadCompl
631
647
  touchSlop = ViewConfiguration.get(context).getScaledTouchSlop();
632
648
  }
633
649
 
634
- void setConfiguration(boolean annotationMode, String annotationTool, boolean annotationEditable, String annotationIdMode, boolean annotationEditingSupported) {
650
+ void setConfiguration(boolean annotationMode, String annotationTool, boolean annotationEditable, String annotationIdMode, boolean annotationEditingSupported, String annotationInkColor, float annotationInkThickness) {
635
651
  annotationModeEnabled = annotationMode;
636
- tool = annotationTool == null ? "select" : annotationTool;
652
+ tool = normalizeAnnotationType(annotationTool == null ? "select" : annotationTool);
637
653
  editable = annotationEditable;
638
654
  idMode = annotationIdMode == null ? "auto" : annotationIdMode;
639
655
  supported = annotationEditingSupported;
656
+ inkColor = TextUtils.isEmpty(annotationInkColor) ? "#111111" : annotationInkColor;
657
+ inkThickness = annotationInkThickness > 0f ? annotationInkThickness : 2f;
640
658
 
641
659
  if (!annotationModeEnabled || !editable || !supported) {
642
660
  commitTextEditingIfNeeded();
@@ -649,6 +667,21 @@ public class PdfView extends PDFView implements OnPageChangeListener,OnLoadCompl
649
667
  invalidate();
650
668
  }
651
669
 
670
+ void deleteSelectedAnnotation() {
671
+ JSONObject selectedAnnotation = getSelectedAnnotation();
672
+ if (selectedAnnotation != null) {
673
+ deleteAnnotation(selectedAnnotation);
674
+ }
675
+ }
676
+
677
+ void deleteAllAnnotations() {
678
+ commitTextEditingIfNeeded();
679
+ draftAnnotations.clear();
680
+ selectedAnnotationId = null;
681
+ clearSelectionInteraction();
682
+ invalidate();
683
+ }
684
+
652
685
  void replaceAnnotations(String json) {
653
686
  draftAnnotations.clear();
654
687
  clearSelectionInteraction();
@@ -677,6 +710,10 @@ public class PdfView extends PDFView implements OnPageChangeListener,OnLoadCompl
677
710
  }
678
711
 
679
712
  JSONObject annotation = new JSONObject(source.toString());
713
+ String type = normalizeAnnotationType(annotation.optString("type", null));
714
+ if (!TextUtils.isEmpty(type)) {
715
+ annotation.put("type", type);
716
+ }
680
717
  if (!annotation.has("id")) {
681
718
  annotation.put("id", nextLocalAnnotationId());
682
719
  }
@@ -764,7 +801,7 @@ public class PdfView extends PDFView implements OnPageChangeListener,OnLoadCompl
764
801
  endInk();
765
802
  return true;
766
803
  }
767
- } else if ("highlight".equals(currentTool) || "underline".equals(currentTool) || "strikeout".equals(currentTool)) {
804
+ } else if ("highlight".equals(currentTool)) {
768
805
  if (action == MotionEvent.ACTION_DOWN) {
769
806
  AnnotationHit hit = hitTest(event.getX(), event.getY());
770
807
  if (hit == null) {
@@ -813,7 +850,7 @@ public class PdfView extends PDFView implements OnPageChangeListener,OnLoadCompl
813
850
  continue;
814
851
  }
815
852
 
816
- String type = annotation.optString("type", "");
853
+ String type = normalizeAnnotationType(annotation.optString("type", ""));
817
854
  RectF rect = viewRectForAnnotation(annotation, pageIndex);
818
855
  if (rect == null && !"ink".equals(type)) {
819
856
  continue;
@@ -864,17 +901,9 @@ public class PdfView extends PDFView implements OnPageChangeListener,OnLoadCompl
864
901
  textPaint.setTextAlign(Paint.Align.LEFT);
865
902
  String text = annotation.optString("text", "");
866
903
  canvas.drawText(text, rect.left + 8f, rect.top + Math.max(20f, textPaint.getTextSize() + 6f), textPaint);
867
- } else if ("highlight".equals(type) || "underline".equals(type) || "strikeout".equals(type)) {
904
+ } else if ("highlight".equals(type)) {
868
905
  fillPaint.setColor(annotationColor(annotation, annotationFillColor(type)));
869
906
  canvas.drawRect(rect, fillPaint);
870
-
871
- if ("underline".equals(type) || "strikeout".equals(type)) {
872
- strokePaint.setStyle(Paint.Style.STROKE);
873
- strokePaint.setStrokeWidth(Math.max(1f, rect.height() * 0.15f));
874
- strokePaint.setColor(annotationColor(annotation, annotationFillColor(type)));
875
- float y = "underline".equals(type) ? rect.bottom - 2f : rect.centerY();
876
- canvas.drawLine(rect.left, y, rect.right, y, strokePaint);
877
- }
878
907
  }
879
908
  }
880
909
 
@@ -895,7 +924,7 @@ public class PdfView extends PDFView implements OnPageChangeListener,OnLoadCompl
895
924
  selectAnnotation(hit.annotation);
896
925
  activeSelectionAnnotation = hit.annotation;
897
926
  activeSelectionHandle = hit.hitPart;
898
- activeSelectionMode = "delete".equals(hit.hitPart) ? "delete" : ("resize".equals(hit.hitPart) ? "resize" : "move");
927
+ activeSelectionMode = "resize".equals(hit.hitPart) ? "resize" : "move";
899
928
  activeSelectionPageIndex = hit.pageIndex;
900
929
  activeSelectionStartBounds = normalizedBoundsForAnnotation(hit.annotation);
901
930
  activeSelectionStartPoints = copyPointsForAnnotation(hit.annotation);
@@ -903,12 +932,6 @@ public class PdfView extends PDFView implements OnPageChangeListener,OnLoadCompl
903
932
  activeSelectionDownY = event.getY();
904
933
  activeSelectionHasMoved = false;
905
934
 
906
- if ("delete".equals(activeSelectionMode)) {
907
- deleteAnnotation(hit.annotation);
908
- clearSelectionInteraction();
909
- return true;
910
- }
911
-
912
935
  return true;
913
936
  }
914
937
 
@@ -972,13 +995,11 @@ public class PdfView extends PDFView implements OnPageChangeListener,OnLoadCompl
972
995
 
973
996
  canvas.drawRoundRect(rect, 4f, 4f, outlinePaint);
974
997
 
975
- RectF deleteHandle = deleteHandleRect(rect);
976
- fillPaint.setColor(Color.argb(235, 210, 48, 48));
977
- canvas.drawOval(deleteHandle, fillPaint);
978
-
979
- RectF resizeHandle = resizeHandleRect(rect);
980
- fillPaint.setColor(Color.argb(235, 34, 68, 170));
981
- canvas.drawRoundRect(resizeHandle, 2f, 2f, fillPaint);
998
+ if (annotationSupportsResize(annotation)) {
999
+ RectF resizeHandle = resizeHandleRect(rect);
1000
+ fillPaint.setColor(Color.argb(235, 34, 68, 170));
1001
+ canvas.drawRoundRect(resizeHandle, 2f, 2f, fillPaint);
1002
+ }
982
1003
  }
983
1004
 
984
1005
  private void clearSelectionInteraction() {
@@ -1212,11 +1233,6 @@ public class PdfView extends PDFView implements OnPageChangeListener,OnLoadCompl
1212
1233
  }
1213
1234
  }
1214
1235
 
1215
- private RectF deleteHandleRect(RectF rect) {
1216
- float size = Math.max(18f, Math.min(rect.width(), rect.height()) * 0.18f);
1217
- return new RectF(rect.right - size, rect.top - size, rect.right, rect.top);
1218
- }
1219
-
1220
1236
  private RectF resizeHandleRect(RectF rect) {
1221
1237
  float size = Math.max(18f, Math.min(rect.width(), rect.height()) * 0.18f);
1222
1238
  return new RectF(rect.right - size, rect.bottom - size, rect.right, rect.bottom);
@@ -1246,12 +1262,8 @@ public class PdfView extends PDFView implements OnPageChangeListener,OnLoadCompl
1246
1262
  }
1247
1263
 
1248
1264
  String hitPart = "body";
1249
- if (includeHandles && selectedAnnotationId != null && selectedAnnotationId.equals(annotation.optString("id", null))) {
1250
- if (deleteHandleRect(rect).contains(x, y)) {
1251
- hitPart = "delete";
1252
- } else if (resizeHandleRect(rect).contains(x, y)) {
1253
- hitPart = "resize";
1254
- }
1265
+ if (includeHandles && selectedAnnotationId != null && selectedAnnotationId.equals(annotation.optString("id", null)) && annotationSupportsResize(annotation) && resizeHandleRect(rect).contains(x, y)) {
1266
+ hitPart = "resize";
1255
1267
  }
1256
1268
 
1257
1269
  return new AnnotationSelectionHit(annotation, pageIndex, rect, hitPart);
@@ -1282,8 +1294,8 @@ public class PdfView extends PDFView implements OnPageChangeListener,OnLoadCompl
1282
1294
  annotation.put("type", "ink");
1283
1295
  annotation.put("points", new JSONArray());
1284
1296
  JSONObject style = new JSONObject();
1285
- style.put("color", "#111111");
1286
- style.put("thickness", 2.0f);
1297
+ style.put("color", inkColor);
1298
+ style.put("thickness", inkThickness);
1287
1299
  annotation.put("style", style);
1288
1300
  draftAnnotations.add(annotation);
1289
1301
  activeInkAnnotation = annotation;
@@ -1325,7 +1337,7 @@ public class PdfView extends PDFView implements OnPageChangeListener,OnLoadCompl
1325
1337
  JSONObject annotation = new JSONObject();
1326
1338
  annotation.put("id", nextLocalAnnotationId());
1327
1339
  annotation.put("page", hit.pageIndex + 1);
1328
- annotation.put("type", type);
1340
+ annotation.put("type", normalizeAnnotationType(type));
1329
1341
  annotation.put("bounds", new JSONObject().put("x", markupStartNormalized.x).put("y", markupStartNormalized.y).put("width", 0).put("height", 0));
1330
1342
  annotation.put("style", new JSONObject());
1331
1343
  draftAnnotations.add(annotation);
@@ -1590,6 +1602,19 @@ public class PdfView extends PDFView implements OnPageChangeListener,OnLoadCompl
1590
1602
  return style == null ? new JSONObject() : style;
1591
1603
  }
1592
1604
 
1605
+ private String normalizeAnnotationType(String type) {
1606
+ if ("underline".equals(type) || "strikeout".equals(type)) {
1607
+ return "highlight";
1608
+ }
1609
+
1610
+ return type;
1611
+ }
1612
+
1613
+ private boolean annotationSupportsResize(JSONObject annotation) {
1614
+ String type = normalizeAnnotationType(annotation.optString("type", ""));
1615
+ return "text".equals(type) || "highlight".equals(type);
1616
+ }
1617
+
1593
1618
  private int annotationColor(JSONObject annotation, int fallback) {
1594
1619
  String color = styleFor(annotation).optString("color", null);
1595
1620
  if (TextUtils.isEmpty(color)) {
@@ -1604,15 +1629,9 @@ public class PdfView extends PDFView implements OnPageChangeListener,OnLoadCompl
1604
1629
  }
1605
1630
 
1606
1631
  private int annotationFillColor(String type) {
1607
- if ("highlight".equals(type)) {
1632
+ if ("highlight".equals(type) || "underline".equals(type) || "strikeout".equals(type)) {
1608
1633
  return Color.argb(90, 255, 230, 60);
1609
1634
  }
1610
- if ("underline".equals(type)) {
1611
- return Color.argb(120, 50, 120, 255);
1612
- }
1613
- if ("strikeout".equals(type)) {
1614
- return Color.argb(120, 255, 50, 50);
1615
- }
1616
1635
 
1617
1636
  return Color.BLACK;
1618
1637
  }
@@ -1700,6 +1719,18 @@ public class PdfView extends PDFView implements OnPageChangeListener,OnLoadCompl
1700
1719
  notifyOnChangeWithMessage("annotationSaveError|Annotation overlay unavailable");
1701
1720
  }
1702
1721
 
1722
+ public void deleteSelectedAnnotation() {
1723
+ if (annotationOverlayView != null) {
1724
+ annotationOverlayView.deleteSelectedAnnotation();
1725
+ }
1726
+ }
1727
+
1728
+ public void deleteAllAnnotations() {
1729
+ if (annotationOverlayView != null) {
1730
+ annotationOverlayView.deleteAllAnnotations();
1731
+ }
1732
+ }
1733
+
1703
1734
  private void showLog(final String str) {
1704
1735
  Log.d("PdfView", str);
1705
1736
  }
@@ -77,6 +77,12 @@ public class RNPDFPdfViewManagerDelegate<T extends View, U extends BaseViewManag
77
77
  case "annotationIdMode":
78
78
  mViewManager.setAnnotationIdMode(view, value == null ? null : (String) value);
79
79
  break;
80
+ case "annotationInkColor":
81
+ mViewManager.setAnnotationInkColor(view, value == null ? null : (String) value);
82
+ break;
83
+ case "annotationInkThickness":
84
+ mViewManager.setAnnotationInkThickness(view, value == null ? 0f : ((Double) value).floatValue());
85
+ break;
80
86
  case "enableAntialiasing":
81
87
  mViewManager.setEnableAntialiasing(view, value == null ? false : (boolean) value);
82
88
  break;
@@ -105,6 +111,12 @@ public class RNPDFPdfViewManagerDelegate<T extends View, U extends BaseViewManag
105
111
  case "saveAnnotations":
106
112
  mViewManager.saveAnnotations(view);
107
113
  break;
114
+ case "deleteSelectedAnnotation":
115
+ mViewManager.deleteSelectedAnnotation(view);
116
+ break;
117
+ case "deleteAllAnnotations":
118
+ mViewManager.deleteAllAnnotations(view);
119
+ break;
108
120
  }
109
121
  }
110
122
  }
@@ -31,6 +31,8 @@ public interface RNPDFPdfViewManagerInterface<T extends View> {
31
31
  void setAnnotationTool(T view, @Nullable String value);
32
32
  void setAnnotationEditable(T view, boolean value);
33
33
  void setAnnotationIdMode(T view, @Nullable String value);
34
+ void setAnnotationInkColor(T view, @Nullable String value);
35
+ void setAnnotationInkThickness(T view, float value);
34
36
  void setEnableAntialiasing(T view, boolean value);
35
37
  void setFitPolicy(T view, int value);
36
38
  void setSpacing(T view, int value);
@@ -38,4 +40,6 @@ public interface RNPDFPdfViewManagerInterface<T extends View> {
38
40
  void setSinglePage(T view, boolean value);
39
41
  void setNativePage(T view, int page);
40
42
  void saveAnnotations(T view);
43
+ void deleteSelectedAnnotation(T view);
44
+ void deleteAllAnnotations(T view);
41
45
  }
@@ -0,0 +1,74 @@
1
+ 'use strict';
2
+
3
+ const LEGACY_MARKUP_TYPES = new Set(['underline', 'strikeout']);
4
+
5
+ export function normalizeAnnotation(annotation) {
6
+ if (!annotation || typeof annotation !== 'object' || Array.isArray(annotation)) {
7
+ return annotation;
8
+ }
9
+
10
+ if (!LEGACY_MARKUP_TYPES.has(annotation.type)) {
11
+ return annotation;
12
+ }
13
+
14
+ return {
15
+ ...annotation,
16
+ type: 'highlight',
17
+ };
18
+ }
19
+
20
+ export function normalizeAnnotationPayload(payload) {
21
+ if (!payload || typeof payload !== 'object') {
22
+ return payload;
23
+ }
24
+
25
+ if (Array.isArray(payload)) {
26
+ return payload.map(normalizeAnnotation);
27
+ }
28
+
29
+ if (!Array.isArray(payload.annotations)) {
30
+ return payload;
31
+ }
32
+
33
+ return {
34
+ ...payload,
35
+ annotations: payload.annotations.map(normalizeAnnotation),
36
+ };
37
+ }
38
+
39
+ export function joinAnnotationMessagePayload(messageParts, startIndex = 1) {
40
+ if (!Array.isArray(messageParts) || messageParts.length <= startIndex) {
41
+ return '';
42
+ }
43
+
44
+ return messageParts.slice(startIndex).join('|');
45
+ }
46
+
47
+ export function parseAnnotationMessagePayload(messageParts, startIndex = 1) {
48
+ const payload = joinAnnotationMessagePayload(messageParts, startIndex);
49
+
50
+ if (!payload) {
51
+ return null;
52
+ }
53
+
54
+ try {
55
+ return normalizeAnnotationPayload(JSON.parse(payload));
56
+ } catch (error) {
57
+ return payload;
58
+ }
59
+ }
60
+
61
+ export function stringifyAnnotationDocument(document, onError) {
62
+ if (!document) {
63
+ return null;
64
+ }
65
+
66
+ try {
67
+ return JSON.stringify(normalizeAnnotationPayload(document));
68
+ } catch (error) {
69
+ if (onError) {
70
+ onError(error);
71
+ }
72
+ return null;
73
+ }
74
+ }
@@ -4,8 +4,7 @@
4
4
  */
5
5
  'use strict';
6
6
 
7
- import codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNativeComponent';
8
- import codegenNativeCommands from 'react-native/Libraries/Utilities/codegenNativeCommands';
7
+ import {codegenNativeComponent, codegenNativeCommands} from 'react-native';
9
8
 
10
9
  type ChangeEvent = $ReadOnly<{|
11
10
  message: ?string,
@@ -35,6 +34,8 @@
35
34
  annotationTool: ?string,
36
35
  annotationEditable: ?boolean,
37
36
  annotationIdMode: ?string,
37
+ annotationInkColor: ?string,
38
+ annotationInkThickness: ?Float,
38
39
  onChange: ?BubblingEventHandler<ChangeEvent>,
39
40
  singlePage: ?boolean,
40
41
  |}>;
@@ -55,10 +56,16 @@
55
56
  +saveAnnotations: (
56
57
  viewRef: React.ElementRef<ComponentType>,
57
58
  ) => void;
59
+ +deleteSelectedAnnotation: (
60
+ viewRef: React.ElementRef<ComponentType>,
61
+ ) => void;
62
+ +deleteAllAnnotations: (
63
+ viewRef: React.ElementRef<ComponentType>,
64
+ ) => void;
58
65
  }
59
66
 
60
67
  export const Commands: NativeCommands = codegenNativeCommands<NativeCommands>({
61
- supportedCommands: ['setNativePage', 'startNativeAutoScroll', 'stopNativeAutoScroll', 'saveAnnotations'],
68
+ supportedCommands: ['setNativePage', 'startNativeAutoScroll', 'stopNativeAutoScroll', 'saveAnnotations', 'deleteSelectedAnnotation', 'deleteAllAnnotations'],
62
69
  });
63
70
 
64
71
  export default codegenNativeComponent<NativeProps>('RNPDFPdfView');
package/index.d.ts CHANGED
@@ -29,7 +29,7 @@ export type Source = {
29
29
 
30
30
  export type AnnotationRotation = 0 | 90 | 180 | 270;
31
31
  export type AnnotationIdMode = 'auto' | 'manual';
32
- export type AnnotationTool = 'select' | 'ink' | 'text' | 'highlight' | 'underline' | 'strikeout';
32
+ export type AnnotationTool = 'select' | 'ink' | 'text' | 'highlight';
33
33
  export type AnnotationTextAlign = 'left' | 'center' | 'right';
34
34
 
35
35
  export type AnnotationPoint = {
@@ -76,7 +76,7 @@ export type TextAnnotation = AnnotationBase & {
76
76
  };
77
77
 
78
78
  export type MarkupAnnotation = AnnotationBase & {
79
- type: 'highlight' | 'underline' | 'strikeout',
79
+ type: 'highlight',
80
80
  bounds: AnnotationBounds,
81
81
  style?: AnnotationStyle,
82
82
  };
@@ -120,11 +120,34 @@ export interface PdfProps {
120
120
  enableRTL?: boolean,
121
121
  enableAnnotationRendering?: boolean,
122
122
  enableDoubleTapZoom?: boolean;
123
+ /**
124
+ * Initial annotation document to render in the overlay.
125
+ */
123
126
  annotations?: AnnotationDocument,
127
+ /**
128
+ * Enable annotation editing mode.
129
+ */
124
130
  annotationMode?: boolean,
131
+ /**
132
+ * Active tool used while annotation editing is enabled.
133
+ */
125
134
  annotationTool?: AnnotationTool,
135
+ /**
136
+ * Allow in-place annotation edits.
137
+ */
126
138
  annotationEditable?: boolean,
139
+ /**
140
+ * Controls how annotation IDs are generated and preserved.
141
+ */
127
142
  annotationIdMode?: AnnotationIdMode,
143
+ /**
144
+ * Default color applied to newly created ink annotations.
145
+ */
146
+ annotationInkColor?: string,
147
+ /**
148
+ * Default thickness applied to newly created ink annotations.
149
+ */
150
+ annotationInkThickness?: number,
128
151
  /**
129
152
  * Only works on iOS. Defaults to `true`.
130
153
  */
@@ -151,7 +174,18 @@ export interface PdfProps {
151
174
 
152
175
  export interface PdfRef {
153
176
  setPage(pageNumber: number): void
177
+ /**
178
+ * Resolves with the current annotation document serialized by native code.
179
+ */
154
180
  saveAnnotations(): Promise<AnnotationDocument>
181
+ /**
182
+ * Deletes the currently selected custom annotation.
183
+ */
184
+ deleteSelectedAnnotation(): void
185
+ /**
186
+ * Deletes all custom annotations in the current overlay draft.
187
+ */
188
+ deleteAllAnnotations(): void
155
189
  /**
156
190
  * Start smooth automatic vertical scrolling using the display refresh rate.
157
191
  * @param dpPerSecond - Scroll speed in density-independent pixels (dp) per second (default: 15). Produces consistent physical speed across screen densities.
package/index.js CHANGED
@@ -23,6 +23,11 @@ import PdfViewNativeComponent, {
23
23
  import ReactNativeBlobUtil from 'react-native-blob-util'
24
24
  import {ViewPropTypes} from 'deprecated-react-native-prop-types';
25
25
  const SHA1 = require('crypto-js/sha1');
26
+ import {
27
+ joinAnnotationMessagePayload,
28
+ parseAnnotationMessagePayload,
29
+ stringifyAnnotationDocument,
30
+ } from './annotationDocumentUtils';
26
31
  import PdfView from './PdfView';
27
32
 
28
33
  export default class Pdf extends Component {
@@ -59,9 +64,11 @@ export default class Pdf extends Component {
59
64
  singlePage: PropTypes.bool,
60
65
  annotations: PropTypes.object,
61
66
  annotationMode: PropTypes.bool,
62
- annotationTool: PropTypes.oneOf(['select', 'ink', 'text', 'highlight', 'underline', 'strikeout']),
67
+ annotationTool: PropTypes.oneOf(['select', 'ink', 'text', 'highlight']),
63
68
  annotationEditable: PropTypes.bool,
64
69
  annotationIdMode: PropTypes.oneOf(['auto', 'manual']),
70
+ annotationInkColor: PropTypes.string,
71
+ annotationInkThickness: PropTypes.number,
65
72
  onLoadComplete: PropTypes.func,
66
73
  onPageChanged: PropTypes.func,
67
74
  onError: PropTypes.func,
@@ -106,6 +113,8 @@ export default class Pdf extends Component {
106
113
  annotationTool: 'select',
107
114
  annotationEditable: true,
108
115
  annotationIdMode: 'auto',
116
+ annotationInkColor: '#111111',
117
+ annotationInkThickness: 2,
109
118
  onLoadProgress: (percent) => {
110
119
  },
111
120
  onLoadComplete: (numberOfPages, path) => {
@@ -423,6 +432,34 @@ export default class Pdf extends Component {
423
432
  });
424
433
  }
425
434
 
435
+ deleteSelectedAnnotation() {
436
+ this._dispatchAnnotationCommand('deleteSelectedAnnotation', PdfViewCommands.deleteSelectedAnnotation);
437
+ }
438
+
439
+ deleteAllAnnotations() {
440
+ this._dispatchAnnotationCommand('deleteAllAnnotations', PdfViewCommands.deleteAllAnnotations);
441
+ }
442
+
443
+ _dispatchAnnotationCommand(commandName, fabricCommand) {
444
+ if (!this._root) {
445
+ return;
446
+ }
447
+
448
+ if (!!global?.nativeFabricUIManager) {
449
+ if (fabricCommand) {
450
+ fabricCommand(this._root);
451
+ }
452
+ return;
453
+ }
454
+
455
+ const ReactNative = require('react-native');
456
+ ReactNative.UIManager.dispatchViewManagerCommand(
457
+ ReactNative.findNodeHandle(this._root),
458
+ commandName,
459
+ [],
460
+ );
461
+ }
462
+
426
463
  startAutoScroll( dpPerSecond = 15, resumeDelay = 3000 ) {
427
464
  this._isAutoScrollActive = true;
428
465
  if (!!global?.nativeFabricUIManager) {
@@ -517,24 +554,17 @@ export default class Pdf extends Component {
517
554
  this._isAutoScrollActive = false;
518
555
  this.props.onAutoScrollEnd && this.props.onAutoScrollEnd();
519
556
  } else if (message[0] === 'annotationSaveComplete') {
520
- message[1] = message.slice(1).join('|');
521
-
522
- let annotationDocument;
523
- try {
524
- annotationDocument = message[1] ? JSON.parse(message[1]) : null;
525
- } catch (e) {
526
- annotationDocument = message[1];
527
- }
557
+ const annotationDocument = parseAnnotationMessagePayload(message);
528
558
 
529
559
  if (this._annotationSavePromise) {
530
560
  this._annotationSavePromise.resolve(annotationDocument);
531
561
  this._annotationSavePromise = null;
532
562
  }
533
563
  } else if (message[0] === 'annotationSaveError') {
534
- message[1] = message.slice(1).join('|');
564
+ const annotationError = joinAnnotationMessagePayload(message);
535
565
 
536
566
  if (this._annotationSavePromise) {
537
- this._annotationSavePromise.reject(new Error(message[1] || 'Annotation save failed'));
567
+ this._annotationSavePromise.reject(new Error(annotationError || 'Annotation save failed'));
538
568
  this._annotationSavePromise = null;
539
569
  }
540
570
  }
@@ -549,16 +579,7 @@ export default class Pdf extends Component {
549
579
  };
550
580
 
551
581
  _getNativeAnnotations = () => {
552
- if (!this.props.annotations) {
553
- return null;
554
- }
555
-
556
- try {
557
- return JSON.stringify(this.props.annotations);
558
- } catch (error) {
559
- this._onError(error);
560
- return null;
561
- }
582
+ return stringifyAnnotationDocument(this.props.annotations, this._onError);
562
583
  };
563
584
 
564
585
  render() {
package/index.js.flow CHANGED
@@ -26,7 +26,7 @@ export type Source = {
26
26
 
27
27
  export type AnnotationRotation = 0 | 90 | 180 | 270;
28
28
  export type AnnotationIdMode = 'auto' | 'manual';
29
- export type AnnotationTool = 'select' | 'ink' | 'text' | 'highlight' | 'underline' | 'strikeout';
29
+ export type AnnotationTool = 'select' | 'ink' | 'text' | 'highlight';
30
30
  export type AnnotationTextAlign = 'left' | 'center' | 'right';
31
31
 
32
32
  export type AnnotationPoint = {
@@ -73,7 +73,7 @@ export type TextAnnotation = AnnotationBase & {
73
73
  };
74
74
 
75
75
  export type MarkupAnnotation = AnnotationBase & {
76
- type: 'highlight' | 'underline' | 'strikeout',
76
+ type: 'highlight',
77
77
  bounds: AnnotationBounds,
78
78
  style?: AnnotationStyle,
79
79
  };
@@ -100,6 +100,8 @@ export type Props = {
100
100
  annotationTool?: AnnotationTool,
101
101
  annotationEditable?: boolean,
102
102
  annotationIdMode?: AnnotationIdMode,
103
+ annotationInkColor?: string,
104
+ annotationInkThickness?: number,
103
105
  enableAnnotationRendering?: boolean,
104
106
  enableAntialiasing?: boolean,
105
107
  enablePaging?: boolean,
@@ -132,4 +134,6 @@ export type Props = {
132
134
  declare export default class Pdf extends Component<Props> {
133
135
  setPage: (pageNumber: number) => void;
134
136
  saveAnnotations: () => Promise<AnnotationDocument>;
137
+ deleteSelectedAnnotation: () => void;
138
+ deleteAllAnnotations: () => void;
135
139
  }
@@ -54,6 +54,8 @@ UIView
54
54
  @property(nonatomic, strong) NSString *annotationTool;
55
55
  @property(nonatomic) BOOL annotationEditable;
56
56
  @property(nonatomic, strong) NSString *annotationIdMode;
57
+ @property(nonatomic, strong) NSString *annotationInkColor;
58
+ @property(nonatomic) float annotationInkThickness;
57
59
  @property(nonatomic) int fitPolicy;
58
60
  @property(nonatomic) int spacing;
59
61
  @property(nonatomic, strong) NSString *password;
@@ -62,6 +64,8 @@ UIView
62
64
  @property(nonatomic, copy) RCTBubblingEventBlock onChange;
63
65
 
64
66
  - (void)saveAnnotations;
67
+ - (void)deleteSelectedAnnotation;
68
+ - (void)deleteAllAnnotations;
65
69
 
66
70
  @property(nonatomic, strong) NSString *selectedText;
67
71
  @property(nonatomic) BOOL enableTextSelection;