@amafil/react-native-pdf-toolkit 1.0.0

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 (202) hide show
  1. package/DoubleTapView.js +125 -0
  2. package/LICENSE +21 -0
  3. package/PdfManager.js +26 -0
  4. package/PdfPageView.js +53 -0
  5. package/PdfView.js +421 -0
  6. package/PdfViewFlatList.js +30 -0
  7. package/PinchZoomView.js +125 -0
  8. package/README.md +450 -0
  9. package/android/.gradle/8.5/checksums/checksums.lock +0 -0
  10. package/android/.gradle/8.5/checksums/md5-checksums.bin +0 -0
  11. package/android/.gradle/8.5/checksums/sha1-checksums.bin +0 -0
  12. package/android/.gradle/8.5/dependencies-accessors/dependencies-accessors.lock +0 -0
  13. package/android/.gradle/8.5/dependencies-accessors/gc.properties +0 -0
  14. package/android/.gradle/8.5/executionHistory/executionHistory.bin +0 -0
  15. package/android/.gradle/8.5/executionHistory/executionHistory.lock +0 -0
  16. package/android/.gradle/8.5/fileChanges/last-build.bin +0 -0
  17. package/android/.gradle/8.5/fileHashes/fileHashes.bin +0 -0
  18. package/android/.gradle/8.5/fileHashes/fileHashes.lock +0 -0
  19. package/android/.gradle/8.5/fileHashes/resourceHashesCache.bin +0 -0
  20. package/android/.gradle/8.5/gc.properties +0 -0
  21. package/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
  22. package/android/.gradle/buildOutputCleanup/cache.properties +2 -0
  23. package/android/.gradle/buildOutputCleanup/outputFiles.bin +0 -0
  24. package/android/.gradle/config.properties +2 -0
  25. package/android/.gradle/file-system.probe +0 -0
  26. package/android/.gradle/vcs-1/gc.properties +0 -0
  27. package/android/.idea/AndroidProjectSystem.xml +6 -0
  28. package/android/.idea/caches/deviceStreaming.xml +1414 -0
  29. package/android/.idea/compiler.xml +6 -0
  30. package/android/.idea/deviceManager.xml +13 -0
  31. package/android/.idea/gradle.xml +17 -0
  32. package/android/.idea/migrations.xml +10 -0
  33. package/android/.idea/misc.xml +10 -0
  34. package/android/.idea/runConfigurations.xml +17 -0
  35. package/android/.idea/vcs.xml +6 -0
  36. package/android/build/.transforms/3337b950908a4f6985ba400cb8386b0b/results.bin +1 -0
  37. package/android/build/.transforms/3337b950908a4f6985ba400cb8386b0b/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/com/facebook/react/viewmanagers/RNPDFPdfViewManagerDelegate.dex +0 -0
  38. package/android/build/.transforms/3337b950908a4f6985ba400cb8386b0b/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/com/facebook/react/viewmanagers/RNPDFPdfViewManagerInterface.dex +0 -0
  39. package/android/build/.transforms/3337b950908a4f6985ba400cb8386b0b/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/org/wonday/pdf/BuildConfig.dex +0 -0
  40. package/android/build/.transforms/3337b950908a4f6985ba400cb8386b0b/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/org/wonday/pdf/PdfManager.dex +0 -0
  41. package/android/build/.transforms/3337b950908a4f6985ba400cb8386b0b/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/org/wonday/pdf/PdfView$1.dex +0 -0
  42. package/android/build/.transforms/3337b950908a4f6985ba400cb8386b0b/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/org/wonday/pdf/PdfView$2.dex +0 -0
  43. package/android/build/.transforms/3337b950908a4f6985ba400cb8386b0b/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/org/wonday/pdf/PdfView$3.dex +0 -0
  44. package/android/build/.transforms/3337b950908a4f6985ba400cb8386b0b/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/org/wonday/pdf/PdfView.dex +0 -0
  45. package/android/build/.transforms/3337b950908a4f6985ba400cb8386b0b/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/org/wonday/pdf/RNPDFPackage.dex +0 -0
  46. package/android/build/.transforms/3337b950908a4f6985ba400cb8386b0b/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/org/wonday/pdf/events/TopChangeEvent.dex +0 -0
  47. package/android/build/.transforms/3337b950908a4f6985ba400cb8386b0b/transformed/bundleLibRuntimeToDirDebug/desugar_graph.bin +0 -0
  48. package/android/build/.transforms/787b9137f14dcc9eebbb21ac62a7be22/results.bin +1 -0
  49. package/android/build/.transforms/787b9137f14dcc9eebbb21ac62a7be22/transformed/classes/classes_dex/classes.dex +0 -0
  50. package/android/build/.transforms/79ca1220a602ed0c9c23366e0e92a6d1/results.bin +1 -0
  51. package/android/build/.transforms/79ca1220a602ed0c9c23366e0e92a6d1/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/com/facebook/react/viewmanagers/RNPDFPdfViewManagerDelegate.dex +0 -0
  52. package/android/build/.transforms/79ca1220a602ed0c9c23366e0e92a6d1/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/com/facebook/react/viewmanagers/RNPDFPdfViewManagerInterface.dex +0 -0
  53. package/android/build/.transforms/79ca1220a602ed0c9c23366e0e92a6d1/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/org/wonday/pdf/BuildConfig.dex +0 -0
  54. package/android/build/.transforms/79ca1220a602ed0c9c23366e0e92a6d1/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/org/wonday/pdf/PdfManager.dex +0 -0
  55. package/android/build/.transforms/79ca1220a602ed0c9c23366e0e92a6d1/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/org/wonday/pdf/PdfView$1.dex +0 -0
  56. package/android/build/.transforms/79ca1220a602ed0c9c23366e0e92a6d1/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/org/wonday/pdf/PdfView$2.dex +0 -0
  57. package/android/build/.transforms/79ca1220a602ed0c9c23366e0e92a6d1/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/org/wonday/pdf/PdfView$3.dex +0 -0
  58. package/android/build/.transforms/79ca1220a602ed0c9c23366e0e92a6d1/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/org/wonday/pdf/PdfView.dex +0 -0
  59. package/android/build/.transforms/79ca1220a602ed0c9c23366e0e92a6d1/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/org/wonday/pdf/RNPDFPackage.dex +0 -0
  60. package/android/build/.transforms/79ca1220a602ed0c9c23366e0e92a6d1/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/org/wonday/pdf/events/TopChangeEvent.dex +0 -0
  61. package/android/build/.transforms/79ca1220a602ed0c9c23366e0e92a6d1/transformed/bundleLibRuntimeToDirDebug/desugar_graph.bin +0 -0
  62. package/android/build/.transforms/c29f40a753b0ae1d85db8c8c5812fc85/results.bin +1 -0
  63. package/android/build/.transforms/c29f40a753b0ae1d85db8c8c5812fc85/transformed/classes/classes_dex/classes.dex +0 -0
  64. package/android/build/generated/source/buildConfig/debug/org/wonday/pdf/BuildConfig.java +12 -0
  65. package/android/build/generated/source/codegen/java/com/facebook/react/viewmanagers/RNPDFPdfViewManagerDelegate.java +99 -0
  66. package/android/build/generated/source/codegen/java/com/facebook/react/viewmanagers/RNPDFPdfViewManagerInterface.java +38 -0
  67. package/android/build/generated/source/codegen/jni/CMakeLists.txt +28 -0
  68. package/android/build/generated/source/codegen/jni/react/renderer/components/rnpdf/ComponentDescriptors.cpp +22 -0
  69. package/android/build/generated/source/codegen/jni/react/renderer/components/rnpdf/ComponentDescriptors.h +24 -0
  70. package/android/build/generated/source/codegen/jni/react/renderer/components/rnpdf/EventEmitters.cpp +24 -0
  71. package/android/build/generated/source/codegen/jni/react/renderer/components/rnpdf/EventEmitters.h +25 -0
  72. package/android/build/generated/source/codegen/jni/react/renderer/components/rnpdf/Props.cpp +132 -0
  73. package/android/build/generated/source/codegen/jni/react/renderer/components/rnpdf/Props.h +50 -0
  74. package/android/build/generated/source/codegen/jni/react/renderer/components/rnpdf/ShadowNodes.cpp +17 -0
  75. package/android/build/generated/source/codegen/jni/react/renderer/components/rnpdf/ShadowNodes.h +32 -0
  76. package/android/build/generated/source/codegen/jni/react/renderer/components/rnpdf/States.cpp +16 -0
  77. package/android/build/generated/source/codegen/jni/react/renderer/components/rnpdf/States.h +20 -0
  78. package/android/build/generated/source/codegen/jni/react/renderer/components/rnpdf/rnpdfJSI-generated.cpp +17 -0
  79. package/android/build/generated/source/codegen/jni/react/renderer/components/rnpdf/rnpdfJSI.h +19 -0
  80. package/android/build/generated/source/codegen/jni/rnpdf-generated.cpp +22 -0
  81. package/android/build/generated/source/codegen/jni/rnpdf.h +24 -0
  82. package/android/build/generated/source/codegen/schema.json +1 -0
  83. package/android/build/intermediates/aapt_friendly_merged_manifests/debug/aapt/AndroidManifest.xml +7 -0
  84. package/android/build/intermediates/aapt_friendly_merged_manifests/debug/aapt/output-metadata.json +18 -0
  85. package/android/build/intermediates/aapt_friendly_merged_manifests/debug/processDebugManifest/aapt/AndroidManifest.xml +7 -0
  86. package/android/build/intermediates/aapt_friendly_merged_manifests/debug/processDebugManifest/aapt/output-metadata.json +18 -0
  87. package/android/build/intermediates/aar_main_jar/debug/syncDebugLibJars/classes.jar +0 -0
  88. package/android/build/intermediates/aar_metadata/debug/aar-metadata.properties +5 -0
  89. package/android/build/intermediates/aar_metadata/debug/writeDebugAarMetadata/aar-metadata.properties +6 -0
  90. package/android/build/intermediates/annotation_processor_list/debug/annotationProcessors.json +1 -0
  91. package/android/build/intermediates/annotation_processor_list/debug/javaPreCompileDebug/annotationProcessors.json +1 -0
  92. package/android/build/intermediates/annotation_processor_list/debugAndroidTest/annotationProcessors.json +1 -0
  93. package/android/build/intermediates/annotation_processor_list/debugUnitTest/annotationProcessors.json +1 -0
  94. package/android/build/intermediates/annotations_typedef_file/debug/extractDebugAnnotations/typedefs.txt +0 -0
  95. package/android/build/intermediates/compile_library_classes_jar/debug/bundleLibCompileToJarDebug/classes.jar +0 -0
  96. package/android/build/intermediates/compile_r_class_jar/debug/generateDebugRFile/R.jar +0 -0
  97. package/android/build/intermediates/compile_symbol_list/debug/generateDebugRFile/R.txt +0 -0
  98. package/android/build/intermediates/incremental/debug/packageDebugResources/compile-file-map.properties +1 -0
  99. package/android/build/intermediates/incremental/debug/packageDebugResources/merger.xml +2 -0
  100. package/android/build/intermediates/incremental/debug-mergeJavaRes/merge-state +0 -0
  101. package/android/build/intermediates/incremental/mergeDebugAssets/merger.xml +2 -0
  102. package/android/build/intermediates/incremental/mergeDebugJniLibFolders/merger.xml +2 -0
  103. package/android/build/intermediates/incremental/mergeDebugShaders/merger.xml +2 -0
  104. package/android/build/intermediates/javac/debug/compileDebugJavaWithJavac/classes/com/facebook/react/viewmanagers/RNPDFPdfViewManagerDelegate.class +0 -0
  105. package/android/build/intermediates/javac/debug/compileDebugJavaWithJavac/classes/com/facebook/react/viewmanagers/RNPDFPdfViewManagerInterface.class +0 -0
  106. package/android/build/intermediates/javac/debug/compileDebugJavaWithJavac/classes/org/wonday/pdf/BuildConfig.class +0 -0
  107. package/android/build/intermediates/javac/debug/compileDebugJavaWithJavac/classes/org/wonday/pdf/PdfManager.class +0 -0
  108. package/android/build/intermediates/javac/debug/compileDebugJavaWithJavac/classes/org/wonday/pdf/PdfView$1.class +0 -0
  109. package/android/build/intermediates/javac/debug/compileDebugJavaWithJavac/classes/org/wonday/pdf/PdfView$2.class +0 -0
  110. package/android/build/intermediates/javac/debug/compileDebugJavaWithJavac/classes/org/wonday/pdf/PdfView$3.class +0 -0
  111. package/android/build/intermediates/javac/debug/compileDebugJavaWithJavac/classes/org/wonday/pdf/PdfView.class +0 -0
  112. package/android/build/intermediates/javac/debug/compileDebugJavaWithJavac/classes/org/wonday/pdf/RNPDFPackage.class +0 -0
  113. package/android/build/intermediates/javac/debug/compileDebugJavaWithJavac/classes/org/wonday/pdf/events/TopChangeEvent.class +0 -0
  114. package/android/build/intermediates/local_only_symbol_list/debug/R-def.txt +2 -0
  115. package/android/build/intermediates/local_only_symbol_list/debug/parseDebugLocalResources/R-def.txt +2 -0
  116. package/android/build/intermediates/manifest_merge_blame_file/debug/manifest-merger-blame-debug-report.txt +8 -0
  117. package/android/build/intermediates/manifest_merge_blame_file/debug/processDebugManifest/manifest-merger-blame-debug-report.txt +7 -0
  118. package/android/build/intermediates/merged_java_res/debug/mergeDebugJavaResource/feature-react-native-pdf.jar +0 -0
  119. package/android/build/intermediates/merged_manifest/debug/AndroidManifest.xml +7 -0
  120. package/android/build/intermediates/merged_manifest/debug/processDebugManifest/AndroidManifest.xml +7 -0
  121. package/android/build/intermediates/navigation_json/debug/extractDeepLinksDebug/navigation.json +1 -0
  122. package/android/build/intermediates/navigation_json/debug/navigation.json +1 -0
  123. package/android/build/intermediates/nested_resources_validation_report/debug/generateDebugResources/nestedResourcesValidationReport.txt +1 -0
  124. package/android/build/intermediates/packaged_manifests/debug/output-metadata.json +18 -0
  125. package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/com/facebook/react/viewmanagers/RNPDFPdfViewManagerDelegate.class +0 -0
  126. package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/com/facebook/react/viewmanagers/RNPDFPdfViewManagerInterface.class +0 -0
  127. package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/org/wonday/pdf/BuildConfig.class +0 -0
  128. package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/org/wonday/pdf/PdfManager.class +0 -0
  129. package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/org/wonday/pdf/PdfView$1.class +0 -0
  130. package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/org/wonday/pdf/PdfView$2.class +0 -0
  131. package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/org/wonday/pdf/PdfView$3.class +0 -0
  132. package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/org/wonday/pdf/PdfView.class +0 -0
  133. package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/org/wonday/pdf/RNPDFPackage.class +0 -0
  134. package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/org/wonday/pdf/events/TopChangeEvent.class +0 -0
  135. package/android/build/intermediates/runtime_library_classes_jar/debug/bundleLibRuntimeToJarDebug/classes.jar +0 -0
  136. package/android/build/intermediates/symbol_list_with_package_name/debug/generateDebugRFile/package-aware-r.txt +1 -0
  137. package/android/build/outputs/aar/react-native-pdf-debug.aar +0 -0
  138. package/android/build/outputs/logs/manifest-merger-debug-report.txt +16 -0
  139. package/android/build/tmp/compileDebugJavaWithJavac/compileTransaction/stash-dir/PdfManager.class.uniqueId3 +0 -0
  140. package/android/build/tmp/compileDebugJavaWithJavac/compileTransaction/stash-dir/PdfManager.class.uniqueId4 +0 -0
  141. package/android/build/tmp/compileDebugJavaWithJavac/compileTransaction/stash-dir/PdfView$1.class.uniqueId0 +0 -0
  142. package/android/build/tmp/compileDebugJavaWithJavac/compileTransaction/stash-dir/PdfView$2.class.uniqueId5 +0 -0
  143. package/android/build/tmp/compileDebugJavaWithJavac/compileTransaction/stash-dir/PdfView$2.class.uniqueId6 +0 -0
  144. package/android/build/tmp/compileDebugJavaWithJavac/compileTransaction/stash-dir/PdfView$3.class.uniqueId4 +0 -0
  145. package/android/build/tmp/compileDebugJavaWithJavac/compileTransaction/stash-dir/PdfView$3.class.uniqueId5 +0 -0
  146. package/android/build/tmp/compileDebugJavaWithJavac/compileTransaction/stash-dir/PdfView.class.uniqueId2 +0 -0
  147. package/android/build/tmp/compileDebugJavaWithJavac/compileTransaction/stash-dir/PdfView.class.uniqueId3 +0 -0
  148. package/android/build/tmp/compileDebugJavaWithJavac/compileTransaction/stash-dir/RNPDFPackage.class.uniqueId1 +0 -0
  149. package/android/build/tmp/compileDebugJavaWithJavac/compileTransaction/stash-dir/RNPDFPackage.class.uniqueId2 +0 -0
  150. package/android/build/tmp/compileDebugJavaWithJavac/compileTransaction/stash-dir/RNPDFPdfViewManagerDelegate.class.uniqueId7 +0 -0
  151. package/android/build/tmp/compileDebugJavaWithJavac/compileTransaction/stash-dir/RNPDFPdfViewManagerInterface.class.uniqueId1 +0 -0
  152. package/android/build/tmp/compileDebugJavaWithJavac/previous-compilation-data.bin +0 -0
  153. package/android/build.gradle +148 -0
  154. package/android/gradle/wrapper/gradle-wrapper.jar +0 -0
  155. package/android/gradle/wrapper/gradle-wrapper.properties +7 -0
  156. package/android/gradle.properties +2 -0
  157. package/android/gradlew +249 -0
  158. package/android/gradlew.bat +92 -0
  159. package/android/local.properties +8 -0
  160. package/android/project.properties +12 -0
  161. package/android/src/main/AndroidManifest.xml +4 -0
  162. package/android/src/main/AndroidManifestNew.xml +4 -0
  163. package/android/src/main/java/org/wonday/pdf/PdfManager.java +196 -0
  164. package/android/src/main/java/org/wonday/pdf/PdfView.java +680 -0
  165. package/android/src/main/java/org/wonday/pdf/RNPDFPackage.java +39 -0
  166. package/android/src/main/java/org/wonday/pdf/events/TopChangeEvent.java +26 -0
  167. package/android/src/paper/java/com/facebook/react/viewmanagers/RNPDFPdfViewManagerDelegate.java +92 -0
  168. package/android/src/paper/java/com/facebook/react/viewmanagers/RNPDFPdfViewManagerInterface.java +35 -0
  169. package/fabric/RNPDFPdfNativeComponent.js +56 -0
  170. package/index.d.ts +83 -0
  171. package/index.js +524 -0
  172. package/index.js.flow +67 -0
  173. package/ios/RNPDFPdf/PdfManager.h +23 -0
  174. package/ios/RNPDFPdf/PdfManager.mm +152 -0
  175. package/ios/RNPDFPdf/RNPDFPdfPageView.h +21 -0
  176. package/ios/RNPDFPdf/RNPDFPdfPageView.mm +185 -0
  177. package/ios/RNPDFPdf/RNPDFPdfPageViewManager.h +18 -0
  178. package/ios/RNPDFPdf/RNPDFPdfPageViewManager.mm +30 -0
  179. package/ios/RNPDFPdf/RNPDFPdfView.h +60 -0
  180. package/ios/RNPDFPdf/RNPDFPdfView.mm +1101 -0
  181. package/ios/RNPDFPdf/RNPDFPdfViewManager.h +18 -0
  182. package/ios/RNPDFPdf/RNPDFPdfViewManager.mm +96 -0
  183. package/ios/RNPDFPdf.xcodeproj/project.pbxproj +321 -0
  184. package/package.json +73 -0
  185. package/react-native-pdf.podspec +30 -0
  186. package/windows/RCTPdf/PropertySheet.props +16 -0
  187. package/windows/RCTPdf/RCTPdf.def +3 -0
  188. package/windows/RCTPdf/RCTPdf.vcxproj +180 -0
  189. package/windows/RCTPdf/RCTPdf.vcxproj.filters +38 -0
  190. package/windows/RCTPdf/RCTPdfControl.cpp +667 -0
  191. package/windows/RCTPdf/RCTPdfControl.h +119 -0
  192. package/windows/RCTPdf/RCTPdfControl.idl +10 -0
  193. package/windows/RCTPdf/RCTPdfControl.xaml +33 -0
  194. package/windows/RCTPdf/RCTPdfViewManager.cpp +69 -0
  195. package/windows/RCTPdf/RCTPdfViewManager.h +51 -0
  196. package/windows/RCTPdf/ReactPackageProvider.cpp +15 -0
  197. package/windows/RCTPdf/ReactPackageProvider.h +16 -0
  198. package/windows/RCTPdf/ReactPackageProvider.idl +9 -0
  199. package/windows/RCTPdf/packages.config +4 -0
  200. package/windows/RCTPdf/pch.cpp +1 -0
  201. package/windows/RCTPdf/pch.h +31 -0
  202. package/windows/README.md +21 -0
package/index.js ADDED
@@ -0,0 +1,524 @@
1
+ /**
2
+ * Copyright (c) 2017-present, Wonday (@wonday.org)
3
+ * All rights reserved.
4
+ *
5
+ * This source code is licensed under the MIT-style license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+
9
+ 'use strict';
10
+ import React, {Component} from 'react';
11
+ import PropTypes from 'prop-types';
12
+ import {
13
+ View,
14
+ Platform,
15
+ StyleSheet,
16
+ Image,
17
+ Text,
18
+ requireNativeComponent
19
+ } from 'react-native';
20
+ import PdfViewNativeComponent, {
21
+ Commands as PdfViewCommands,
22
+ } from './fabric/RNPDFPdfNativeComponent';
23
+ import ReactNativeBlobUtil from 'react-native-blob-util'
24
+ import {ViewPropTypes} from 'deprecated-react-native-prop-types';
25
+ const SHA1 = require('crypto-js/sha1');
26
+ import PdfView from './PdfView';
27
+
28
+ export default class Pdf extends Component {
29
+
30
+ static propTypes = {
31
+ ...ViewPropTypes,
32
+ source: PropTypes.oneOfType([
33
+ PropTypes.shape({
34
+ uri: PropTypes.string,
35
+ cache: PropTypes.bool,
36
+ cacheFileName: PropTypes.string,
37
+ expiration: PropTypes.number,
38
+ }),
39
+ // Opaque type returned by require('./test.pdf')
40
+ PropTypes.number,
41
+ ]).isRequired,
42
+ page: PropTypes.number,
43
+ scale: PropTypes.number,
44
+ minScale: PropTypes.number,
45
+ maxScale: PropTypes.number,
46
+ horizontal: PropTypes.bool,
47
+ spacing: PropTypes.number,
48
+ password: PropTypes.string,
49
+ renderActivityIndicator: PropTypes.func,
50
+ enableAntialiasing: PropTypes.bool,
51
+ enableAnnotationRendering: PropTypes.bool,
52
+ showsHorizontalScrollIndicator: PropTypes.bool,
53
+ showsVerticalScrollIndicator: PropTypes.bool,
54
+ scrollEnabled: PropTypes.bool,
55
+ enablePaging: PropTypes.bool,
56
+ enableRTL: PropTypes.bool,
57
+ fitPolicy: PropTypes.number,
58
+ trustAllCerts: PropTypes.bool,
59
+ singlePage: PropTypes.bool,
60
+ onLoadComplete: PropTypes.func,
61
+ onPageChanged: PropTypes.func,
62
+ onError: PropTypes.func,
63
+ onPageSingleTap: PropTypes.func,
64
+ onScaleChanged: PropTypes.func,
65
+ onPressLink: PropTypes.func,
66
+ onAutoScrollEnd: PropTypes.func,
67
+
68
+ // Props that are not available in the earlier react native version, added to prevent crashed on android
69
+ accessibilityLabel: PropTypes.string,
70
+ importantForAccessibility: PropTypes.string,
71
+ renderToHardwareTextureAndroid: PropTypes.string,
72
+ testID: PropTypes.string,
73
+ onLayout: PropTypes.bool,
74
+ accessibilityLiveRegion: PropTypes.string,
75
+ accessibilityComponentType: PropTypes.string,
76
+ };
77
+
78
+ static defaultProps = {
79
+ password: "",
80
+ scale: 1,
81
+ minScale: 1,
82
+ maxScale: 3,
83
+ spacing: 10,
84
+ fitPolicy: 2, //fit both
85
+ horizontal: false,
86
+ page: 1,
87
+ enableAntialiasing: true,
88
+ enableAnnotationRendering: true,
89
+ showsHorizontalScrollIndicator: true,
90
+ showsVerticalScrollIndicator: true,
91
+ scrollEnabled: true,
92
+ enablePaging: false,
93
+ enableRTL: false,
94
+ trustAllCerts: true,
95
+ usePDFKit: true,
96
+ singlePage: false,
97
+ onLoadProgress: (percent) => {
98
+ },
99
+ onLoadComplete: (numberOfPages, path) => {
100
+ },
101
+ onPageChanged: (page, numberOfPages) => {
102
+ },
103
+ onError: (error) => {
104
+ },
105
+ onPageSingleTap: (page, x, y) => {
106
+ },
107
+ onScaleChanged: (scale) => {
108
+ },
109
+ onPressLink: (url) => {
110
+ },
111
+ onAutoScrollEnd: () => {
112
+ },
113
+ };
114
+
115
+ constructor(props) {
116
+
117
+ super(props);
118
+ this.state = {
119
+ path: '',
120
+ isDownloaded: false,
121
+ progress: 0,
122
+ };
123
+
124
+ this.lastRNBFTask = null;
125
+
126
+ }
127
+
128
+ componentDidUpdate(prevProps) {
129
+
130
+ const nextSource = Image.resolveAssetSource(this.props.source);
131
+ const curSource = Image.resolveAssetSource(prevProps.source);
132
+
133
+ if ((nextSource.uri !== curSource.uri)) {
134
+ // if has download task, then cancel it.
135
+ if (this.lastRNBFTask && this.lastRNBFTask.cancel) {
136
+ this.lastRNBFTask.cancel(err => {
137
+ this._loadFromSource(this.props.source);
138
+ });
139
+ this.lastRNBFTask = null;
140
+ } else {
141
+ this._loadFromSource(this.props.source);
142
+ }
143
+ }
144
+ }
145
+
146
+ componentDidMount() {
147
+ this._mounted = true;
148
+ this._loadFromSource(this.props.source);
149
+ }
150
+
151
+ componentWillUnmount() {
152
+ this._mounted = false;
153
+ this.stopAutoScroll();
154
+ if (this.lastRNBFTask) {
155
+ // this.lastRNBFTask.cancel(err => {
156
+ // });
157
+ this.lastRNBFTask = null;
158
+ }
159
+
160
+ }
161
+
162
+ _loadFromSource = (newSource) => {
163
+
164
+ const source = Image.resolveAssetSource(newSource) || {};
165
+
166
+ let uri = source.uri || '';
167
+ // first set to initial state
168
+ if (this._mounted) {
169
+ this.setState({isDownloaded: false, path: '', progress: 0});
170
+ }
171
+ const filename = source.cacheFileName || SHA1(uri) + '.pdf';
172
+ const cacheFile = ReactNativeBlobUtil.fs.dirs.CacheDir + '/' + filename;
173
+
174
+ if (source.cache) {
175
+ ReactNativeBlobUtil.fs
176
+ .stat(cacheFile)
177
+ .then(stats => {
178
+ if (!Boolean(source.expiration) || (source.expiration * 1000 + stats.lastModified) > (new Date().getTime())) {
179
+ if (this._mounted) {
180
+ this.setState({path: cacheFile, isDownloaded: true});
181
+ }
182
+ } else {
183
+ // cache expirated then reload it
184
+ this._prepareFile(source);
185
+ }
186
+ })
187
+ .catch(() => {
188
+ this._prepareFile(source);
189
+ })
190
+
191
+ } else {
192
+ this._prepareFile(source);
193
+ }
194
+ };
195
+
196
+ _prepareFile = async (source) => {
197
+
198
+ try {
199
+ if (source.uri) {
200
+ let uri = source.uri || '';
201
+
202
+ const isNetwork = !!(uri && uri.match(/^https?:\/\//));
203
+ const isAsset = !!(uri && uri.match(/^bundle-assets:\/\//));
204
+ const isBase64 = !!(uri && uri.match(/^data:application\/pdf;base64/));
205
+
206
+ const filename = source.cacheFileName || SHA1(uri) + '.pdf';
207
+ const cacheFile = ReactNativeBlobUtil.fs.dirs.CacheDir + '/' + filename;
208
+
209
+ // delete old cache file
210
+ this._unlinkFile(cacheFile);
211
+
212
+ if (isNetwork) {
213
+ this._downloadFile(source, cacheFile);
214
+ } else if (isAsset) {
215
+ ReactNativeBlobUtil.fs
216
+ .cp(uri, cacheFile)
217
+ .then(() => {
218
+ if (this._mounted) {
219
+ this.setState({path: cacheFile, isDownloaded: true, progress: 1});
220
+ }
221
+ })
222
+ .catch(async (error) => {
223
+ this._unlinkFile(cacheFile);
224
+ this._onError(error);
225
+ })
226
+ } else if (isBase64) {
227
+ let data = uri.replace(/data:application\/pdf;base64,/i, '');
228
+ ReactNativeBlobUtil.fs
229
+ .writeFile(cacheFile, data, 'base64')
230
+ .then(() => {
231
+ if (this._mounted) {
232
+ this.setState({path: cacheFile, isDownloaded: true, progress: 1});
233
+ }
234
+ })
235
+ .catch(async (error) => {
236
+ this._unlinkFile(cacheFile);
237
+ this._onError(error)
238
+ });
239
+ } else {
240
+ if (this._mounted) {
241
+ this.setState({
242
+ path: decodeURIComponent(uri.replace(/file:\/\//i, '')),
243
+ isDownloaded: true,
244
+ });
245
+ }
246
+ }
247
+ } else {
248
+ this._onError(new Error('no pdf source!'));
249
+ }
250
+ } catch (e) {
251
+ this._onError(e)
252
+ }
253
+
254
+
255
+ };
256
+
257
+ _downloadFile = async (source, cacheFile) => {
258
+
259
+ if (this.lastRNBFTask) {
260
+ this.lastRNBFTask.cancel(err => {
261
+ });
262
+ this.lastRNBFTask = null;
263
+ }
264
+
265
+ const tempCacheFile = cacheFile + '.tmp';
266
+ this._unlinkFile(tempCacheFile);
267
+
268
+ this.lastRNBFTask = ReactNativeBlobUtil.config({
269
+ // response data will be saved to this path if it has access right.
270
+ path: tempCacheFile,
271
+ trusty: this.props.trustAllCerts,
272
+ })
273
+ .fetch(
274
+ source.method ? source.method : 'GET',
275
+ source.uri,
276
+ source.headers ? source.headers : {},
277
+ source.body ? source.body : ""
278
+ )
279
+ // listen to download progress event
280
+ .progress((received, total) => {
281
+ this.props.onLoadProgress && this.props.onLoadProgress(received / total);
282
+ if (this._mounted) {
283
+ this.setState({progress: received / total});
284
+ }
285
+ })
286
+ .catch(async (error) => {
287
+ this._onError(error);
288
+ });
289
+
290
+ this.lastRNBFTask
291
+ .then(async (res) => {
292
+
293
+ this.lastRNBFTask = null;
294
+
295
+ if (res && res.respInfo && res.respInfo.headers && !res.respInfo.headers["Content-Encoding"] && !res.respInfo.headers["Transfer-Encoding"] && res.respInfo.headers["Content-Length"]) {
296
+ const expectedContentLength = res.respInfo.headers["Content-Length"];
297
+ let actualContentLength;
298
+
299
+ try {
300
+ const fileStats = await ReactNativeBlobUtil.fs.stat(res.path());
301
+
302
+ if (!fileStats || !fileStats.size) {
303
+ throw new Error("FileNotFound:" + source.uri);
304
+ }
305
+
306
+ actualContentLength = fileStats.size;
307
+ } catch (error) {
308
+ throw new Error("DownloadFailed:" + source.uri);
309
+ }
310
+
311
+ if (expectedContentLength != actualContentLength) {
312
+ throw new Error("DownloadFailed:" + source.uri);
313
+ }
314
+ }
315
+
316
+ this._unlinkFile(cacheFile);
317
+ ReactNativeBlobUtil.fs
318
+ .cp(tempCacheFile, cacheFile)
319
+ .then(() => {
320
+ if (this._mounted) {
321
+ this.setState({path: cacheFile, isDownloaded: true, progress: 1});
322
+ }
323
+ this._unlinkFile(tempCacheFile);
324
+ })
325
+ .catch(async (error) => {
326
+ throw error;
327
+ });
328
+ })
329
+ .catch(async (error) => {
330
+ this._unlinkFile(tempCacheFile);
331
+ this._unlinkFile(cacheFile);
332
+ this._onError(error);
333
+ });
334
+
335
+ };
336
+
337
+ _unlinkFile = async (file) => {
338
+ try {
339
+ await ReactNativeBlobUtil.fs.unlink(file);
340
+ } catch (e) {
341
+
342
+ }
343
+ }
344
+
345
+ setNativeProps = nativeProps => {
346
+ if (this._root){
347
+ this._root.setNativeProps(nativeProps);
348
+ }
349
+ };
350
+
351
+ setPage( pageNumber ) {
352
+ if ( (pageNumber === null) || (isNaN(pageNumber)) ) {
353
+ throw new Error('Specified pageNumber is not a number');
354
+ }
355
+ if (!!global?.nativeFabricUIManager ) {
356
+ if (this._root) {
357
+ PdfViewCommands.setNativePage(
358
+ this._root,
359
+ pageNumber,
360
+ );
361
+ }
362
+ } else {
363
+ this.setNativeProps({
364
+ page: pageNumber
365
+ });
366
+ }
367
+
368
+ }
369
+
370
+ startAutoScroll( pixels = 15, resumeDelay = 3000 ) {
371
+ this._isAutoScrollActive = true;
372
+ if (!!global?.nativeFabricUIManager) {
373
+ if (this._root) {
374
+ PdfViewCommands.startNativeAutoScroll(
375
+ this._root,
376
+ pixels,
377
+ resumeDelay,
378
+ );
379
+ }
380
+ } else {
381
+ const ReactNative = require('react-native');
382
+ ReactNative.UIManager.dispatchViewManagerCommand(
383
+ ReactNative.findNodeHandle(this._root),
384
+ 'startNativeAutoScroll',
385
+ [pixels, resumeDelay],
386
+ );
387
+ }
388
+ }
389
+
390
+ stopAutoScroll() {
391
+ this._isAutoScrollActive = false;
392
+ if (!!global?.nativeFabricUIManager) {
393
+ if (this._root) {
394
+ PdfViewCommands.stopNativeAutoScroll(
395
+ this._root,
396
+ );
397
+ }
398
+ } else {
399
+ if (this._root) {
400
+ const ReactNative = require('react-native');
401
+ ReactNative.UIManager.dispatchViewManagerCommand(
402
+ ReactNative.findNodeHandle(this._root),
403
+ 'stopNativeAutoScroll',
404
+ [],
405
+ );
406
+ }
407
+ }
408
+ }
409
+
410
+ _onChange = (event) => {
411
+
412
+ let message = event.nativeEvent.message.split('|');
413
+ //__DEV__ && console.log("onChange: " + message);
414
+ if (message.length > 0) {
415
+ if (message.length > 5) {
416
+ message[4] = message.splice(4).join('|');
417
+ }
418
+ if (message[0] === 'loadComplete') {
419
+ let tableContents;
420
+ try {
421
+ tableContents = message[4]&&JSON.parse(message[4]);
422
+ } catch(e) {
423
+ tableContents = message[4];
424
+ }
425
+ this.props.onLoadComplete && this.props.onLoadComplete(Number(message[1]), this.state.path, {
426
+ width: Number(message[2]),
427
+ height: Number(message[3]),
428
+ },
429
+ tableContents
430
+ );
431
+ } else if (message[0] === 'pageChanged') {
432
+ this.props.onPageChanged && this.props.onPageChanged(Number(message[1]), Number(message[2]));
433
+ } else if (message[0] === 'error') {
434
+ this._onError(new Error(message[1]));
435
+ } else if (message[0] === 'pageSingleTap') {
436
+ this.props.onPageSingleTap && this.props.onPageSingleTap(Number(message[1]), Number(message[2]), Number(message[3]));
437
+ } else if (message[0] === 'scaleChanged') {
438
+ this.props.onScaleChanged && this.props.onScaleChanged(Number(message[1]));
439
+ } else if (message[0] === 'linkPressed') {
440
+ this.props.onPressLink && this.props.onPressLink(message[1]);
441
+ } else if (message[0] === 'autoScrollEnd') {
442
+ this._isAutoScrollActive = false;
443
+ this.props.onAutoScrollEnd && this.props.onAutoScrollEnd();
444
+ }
445
+ }
446
+
447
+ };
448
+
449
+ _onError = (error) => {
450
+
451
+ this.props.onError && this.props.onError(error);
452
+
453
+ };
454
+
455
+ render() {
456
+ if (Platform.OS === "android" || Platform.OS === "ios" || Platform.OS === "windows") {
457
+ return (
458
+ <View style={[this.props.style,{overflow: 'hidden'}]}>
459
+ {!this.state.isDownloaded?
460
+ (<View
461
+ style={[styles.progressContainer, this.props.progressContainerStyle]}
462
+ >
463
+ {this.props.renderActivityIndicator
464
+ ? this.props.renderActivityIndicator(this.state.progress)
465
+ : <Text>{`${(this.state.progress * 100).toFixed(2)}%`}</Text>}
466
+ </View>):(
467
+ Platform.OS === "android" || Platform.OS === "windows"?(
468
+ <PdfCustom
469
+ ref={component => (this._root = component)}
470
+ {...this.props}
471
+ style={[{flex:1,backgroundColor: '#EEE'}, this.props.style]}
472
+ path={this.state.path}
473
+ onChange={this._onChange}
474
+ />
475
+ ):(
476
+ this.props.usePDFKit ?(
477
+ <PdfCustom
478
+ ref={component => (this._root = component)}
479
+ {...this.props}
480
+ style={[{backgroundColor: '#EEE',overflow: 'hidden'}, this.props.style]}
481
+ path={this.state.path}
482
+ onChange={this._onChange}
483
+ />
484
+ ):(<PdfView
485
+ {...this.props}
486
+ style={[{backgroundColor: '#EEE',overflow: 'hidden'}, this.props.style]}
487
+ path={this.state.path}
488
+ onLoadComplete={this.props.onLoadComplete}
489
+ onPageChanged={this.props.onPageChanged}
490
+ onError={this._onError}
491
+ onPageSingleTap={this.props.onPageSingleTap}
492
+ onScaleChanged={this.props.onScaleChanged}
493
+ onPressLink={this.props.onPressLink}
494
+ />)
495
+ )
496
+ )}
497
+ </View>);
498
+ } else {
499
+ return (null);
500
+ }
501
+
502
+
503
+ }
504
+ }
505
+
506
+ if (Platform.OS === "android" || Platform.OS === "ios") {
507
+ var PdfCustom = PdfViewNativeComponent;
508
+ } else if (Platform.OS === "windows") {
509
+ var PdfCustom = requireNativeComponent('RCTPdf', Pdf, {
510
+ nativeOnly: {path: true, onChange: true},
511
+ })
512
+ }
513
+
514
+ const styles = StyleSheet.create({
515
+ progressContainer: {
516
+ flex: 1,
517
+ justifyContent: 'center',
518
+ alignItems: 'center'
519
+ },
520
+ progressBar: {
521
+ width: 200,
522
+ height: 2
523
+ }
524
+ });
package/index.js.flow ADDED
@@ -0,0 +1,67 @@
1
+ /**
2
+ * @flow strict
3
+ */
4
+
5
+ import { Component } from 'react';
6
+
7
+ import type { Node } from 'react';
8
+ import type { FormField, Methods } from 'rn-fetch-blob';
9
+ import type { ViewStyleProp } from 'react-native/Libraries/StyleSheet/StyleSheet'
10
+
11
+ export type AssetId = number;
12
+
13
+ export type FitWidth = 0;
14
+ export type FitHeight = 1;
15
+ export type FitBoth = 2;
16
+
17
+ export type Source = {
18
+ body?: string | FormField[],
19
+ cache?: boolean,
20
+ cacheFileName?: string,
21
+ expiration?: number,
22
+ headers?: { [key: string]: string },
23
+ method?: Methods,
24
+ uri: string
25
+ };
26
+
27
+ export type TableContent = {
28
+ children: TableContent[],
29
+ mNativePtr: number,
30
+ pageIdx: number,
31
+ title: string,
32
+ };
33
+
34
+ export type Props = {
35
+ renderActivityIndicator?: (progress: number) => Node,
36
+ enableAnnotationRendering?: boolean,
37
+ enableAntialiasing?: boolean,
38
+ enablePaging?: boolean,
39
+ enableRTL?: boolean,
40
+ fitPolicy?: FitWidth | FitHeight | FitBoth,
41
+ horizontal?: boolean,
42
+ showsHorizontalScrollIndicator?: boolean,
43
+ showsVerticalScrollIndicator?: boolean,
44
+ scrollEnabled?: boolean,
45
+ maxScale?: number,
46
+ minScale?: number,
47
+ singlePage?: boolean,
48
+ onError?: (error: Error) => void,
49
+ onLoadComplete?: (numberOfPages: number, path: string, size: { height: number, width: number }, tableContents: ?TableContent[]) => void,
50
+ onLoadProgress?: (percent: number) => void,
51
+ onPageChanged?: (page: number, numberOfPages: number) => void,
52
+ onPageSingleTap?: (page: number, x: number, y: number) => void,
53
+ onScaleChanged?: (scale: number) => void,
54
+ onPressLink?: (url: string) => void,
55
+ page?: number,
56
+ password?: string,
57
+ progressContainerStyle?: ViewStyleProp,
58
+ scale?: number,
59
+ source: AssetId | Source,
60
+ spacing?: number,
61
+ style?: ViewStyleProp,
62
+ testID?: string
63
+ };
64
+
65
+ declare export default class Pdf extends Component<Props> {
66
+ setPage: (pageNumber: number) => void;
67
+ }
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Copyright (c) 2017-present, Wonday (@wonday.org)
3
+ * All rights reserved.
4
+ *
5
+ * This source code is licensed under the MIT-style license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+
9
+ #import <Foundation/Foundation.h>
10
+ #import <UIKit/UIKit.h>
11
+
12
+ #if __has_include(<React/RCTAssert.h>)
13
+ #import <React/RCTBridgeModule.h>
14
+ #else
15
+ #import "RCTBridgeModule.h"
16
+ #endif
17
+
18
+
19
+ @interface PdfManager : NSObject <RCTBridgeModule>
20
+
21
+ + (CGPDFDocumentRef) getPdf:(NSUInteger) index;
22
+
23
+ @end