react-native-rectangle-doc-scanner 6.0.0 → 7.1.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.
@@ -47,8 +47,11 @@ android {
47
47
  sourceSets {
48
48
  main {
49
49
  java.srcDirs += 'src/main/kotlin'
50
+ java.srcDirs += 'src/common/kotlin'
50
51
  if (hasVisionCamera) {
51
52
  java.srcDirs += 'src/visioncamera/kotlin'
53
+ } else {
54
+ java.srcDirs += 'src/camera2/kotlin'
52
55
  }
53
56
  }
54
57
  }
@@ -63,28 +66,31 @@ dependencies {
63
66
  implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
64
67
  implementation "com.facebook.react:react-native:+"
65
68
 
66
- // CameraX dependencies
67
- def camerax_version = "1.3.0"
68
- implementation "androidx.camera:camera-core:${camerax_version}"
69
- implementation "androidx.camera:camera-camera2:${camerax_version}"
70
- implementation "androidx.camera:camera-lifecycle:${camerax_version}"
71
- implementation "androidx.camera:camera-view:${camerax_version}"
72
-
73
- // OpenCV for document detection
69
+ // OpenCV for document detection (common)
74
70
  implementation 'org.opencv:opencv:4.9.0'
75
71
 
76
- // ML Kit object detection for live rectangle hints
77
- implementation 'com.google.mlkit:object-detection:17.0.1'
78
-
79
- // Coroutines for async operations
72
+ // Coroutines for async operations (common)
80
73
  implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.3'
81
74
  implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.7.3'
82
75
 
83
- // AndroidX
76
+ // AndroidX (common)
84
77
  implementation 'androidx.core:core-ktx:1.10.1'
85
78
  implementation 'androidx.appcompat:appcompat:1.6.1'
86
79
 
80
+ // CameraX core is needed for ImageProxy in VisionCamera frame processor
81
+ def camerax_version = "1.3.0"
82
+ implementation "androidx.camera:camera-core:${camerax_version}"
83
+
87
84
  if (hasVisionCamera) {
85
+ // VisionCamera mode - include VisionCamera dependency
88
86
  implementation project(':react-native-vision-camera')
87
+ } else {
88
+ // Camera2 mode - include additional CameraX and ML Kit dependencies
89
+ implementation "androidx.camera:camera-camera2:${camerax_version}"
90
+ implementation "androidx.camera:camera-lifecycle:${camerax_version}"
91
+ implementation "androidx.camera:camera-view:${camerax_version}"
92
+
93
+ // ML Kit object detection for live rectangle hints
94
+ implementation 'com.google.mlkit:object-detection:17.0.1'
89
95
  }
90
96
  }
@@ -43,15 +43,22 @@ class DocumentScannerModule(reactContext: ReactApplicationContext) :
43
43
  try {
44
44
  val view = uiManager.resolveView(tag)
45
45
 
46
- if (view is DocumentScannerView) {
47
- Log.d(TAG, "Found DocumentScannerView, triggering capture with promise")
48
-
49
- // Pass promise to view so it can be resolved when capture completes
50
- // This matches iOS behavior where promise is resolved with actual image data
51
- view.captureWithPromise(promise)
52
- } else {
53
- Log.e(TAG, "View with tag $tag is not DocumentScannerView: ${view?.javaClass?.simpleName}")
54
- promise.reject("INVALID_VIEW", "View is not a DocumentScannerView")
46
+ // Use reflection to avoid compile-time dependency on DocumentScannerView
47
+ try {
48
+ val docScannerViewClass = Class.forName("com.reactnativerectangledocscanner.DocumentScannerView")
49
+ if (docScannerViewClass.isInstance(view)) {
50
+ Log.d(TAG, "Found DocumentScannerView, triggering capture with promise")
51
+
52
+ // Pass promise to view so it can be resolved when capture completes
53
+ val captureMethod = docScannerViewClass.getMethod("captureWithPromise", Promise::class.java)
54
+ captureMethod.invoke(view, promise)
55
+ } else {
56
+ Log.e(TAG, "View with tag $tag is not DocumentScannerView: ${view?.javaClass?.simpleName}")
57
+ promise.reject("INVALID_VIEW", "View is not a DocumentScannerView")
58
+ }
59
+ } catch (e: ClassNotFoundException) {
60
+ Log.e(TAG, "DocumentScannerView not available (VisionCamera mode)", e)
61
+ promise.reject("VIEW_NOT_AVAILABLE", "Camera2 views not available in VisionCamera mode")
55
62
  }
56
63
  } catch (e: Exception) {
57
64
  Log.e(TAG, "Error resolving view", e)
@@ -19,10 +19,28 @@ class DocumentScannerPackage : ReactPackage {
19
19
  }
20
20
 
21
21
  override fun createViewManagers(reactContext: ReactApplicationContext): List<ViewManager<*, *>> {
22
- return listOf(
23
- DocumentScannerViewManager(),
24
- CameraViewManager()
25
- )
22
+ // Only register Camera2-based view managers if VisionCamera is not available
23
+ return try {
24
+ Class.forName(VISION_CAMERA_REGISTRY)
25
+ // VisionCamera is available, no need to register Camera2 view managers
26
+ emptyList()
27
+ } catch (e: ClassNotFoundException) {
28
+ // VisionCamera not available, register Camera2 view managers using reflection
29
+ try {
30
+ val viewManagers = mutableListOf<ViewManager<*, *>>()
31
+
32
+ val docScannerViewManagerClass = Class.forName("com.reactnativerectangledocscanner.DocumentScannerViewManager")
33
+ val cameraViewManagerClass = Class.forName("com.reactnativerectangledocscanner.CameraViewManager")
34
+
35
+ viewManagers.add(docScannerViewManagerClass.newInstance() as ViewManager<*, *>)
36
+ viewManagers.add(cameraViewManagerClass.newInstance() as ViewManager<*, *>)
37
+
38
+ viewManagers
39
+ } catch (e: Exception) {
40
+ Log.e(TAG, "Failed to instantiate Camera2 view managers", e)
41
+ emptyList()
42
+ }
43
+ }
26
44
  }
27
45
 
28
46
  private fun registerVisionCameraPlugin() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-rectangle-doc-scanner",
3
- "version": "6.0.0",
3
+ "version": "7.1.0",
4
4
  "description": "Native-backed document scanner for React Native with customizable overlays.",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",