react-native-rectangle-doc-scanner 5.0.0 → 7.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.
- package/android/build.gradle +17 -13
- package/android/src/main/kotlin/com/reactnativerectangledocscanner/DocumentScannerPackage.kt +12 -4
- package/dist/DocScanner.js +21 -4
- package/package.json +1 -1
- package/src/DocScanner.tsx +23 -24
- /package/android/src/{main → camera2}/kotlin/com/reactnativerectangledocscanner/CameraController.kt +0 -0
- /package/android/src/{main → camera2}/kotlin/com/reactnativerectangledocscanner/CameraView.kt +0 -0
- /package/android/src/{main → camera2}/kotlin/com/reactnativerectangledocscanner/CameraViewManager.kt +0 -0
- /package/android/src/{main → camera2}/kotlin/com/reactnativerectangledocscanner/DocumentScannerView.kt +0 -0
- /package/android/src/{main → camera2}/kotlin/com/reactnativerectangledocscanner/DocumentScannerViewManager.kt +0 -0
- /package/android/src/{main → camera2}/kotlin/com/reactnativerectangledocscanner/ImageProxyExt.kt +0 -0
- /package/android/src/{main → common}/kotlin/com/reactnativerectangledocscanner/DocumentDetector.kt +0 -0
- /package/android/src/{main → common}/kotlin/com/reactnativerectangledocscanner/ImageProcessor.kt +0 -0
package/android/build.gradle
CHANGED
|
@@ -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,29 @@ dependencies {
|
|
|
63
66
|
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
|
64
67
|
implementation "com.facebook.react:react-native:+"
|
|
65
68
|
|
|
66
|
-
//
|
|
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
|
-
//
|
|
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
|
|
|
87
80
|
if (hasVisionCamera) {
|
|
81
|
+
// VisionCamera mode - only include VisionCamera dependency
|
|
88
82
|
implementation project(':react-native-vision-camera')
|
|
83
|
+
} else {
|
|
84
|
+
// Camera2 mode - include CameraX and ML Kit dependencies
|
|
85
|
+
def camerax_version = "1.3.0"
|
|
86
|
+
implementation "androidx.camera:camera-core:${camerax_version}"
|
|
87
|
+
implementation "androidx.camera:camera-camera2:${camerax_version}"
|
|
88
|
+
implementation "androidx.camera:camera-lifecycle:${camerax_version}"
|
|
89
|
+
implementation "androidx.camera:camera-view:${camerax_version}"
|
|
90
|
+
|
|
91
|
+
// ML Kit object detection for live rectangle hints
|
|
92
|
+
implementation 'com.google.mlkit:object-detection:17.0.1'
|
|
89
93
|
}
|
|
90
94
|
}
|
package/android/src/main/kotlin/com/reactnativerectangledocscanner/DocumentScannerPackage.kt
CHANGED
|
@@ -19,10 +19,18 @@ class DocumentScannerPackage : ReactPackage {
|
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
override fun createViewManagers(reactContext: ReactApplicationContext): List<ViewManager<*, *>> {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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
|
|
29
|
+
listOf(
|
|
30
|
+
DocumentScannerViewManager(),
|
|
31
|
+
CameraViewManager()
|
|
32
|
+
)
|
|
33
|
+
}
|
|
26
34
|
}
|
|
27
35
|
|
|
28
36
|
private fun registerVisionCameraPlugin() {
|
package/dist/DocScanner.js
CHANGED
|
@@ -422,10 +422,7 @@ const VisionCameraScanner = (0, react_1.forwardRef)(({ onCapture, overlayColor =
|
|
|
422
422
|
showManualCaptureButton && (react_1.default.createElement(react_native_1.TouchableOpacity, { style: styles.button, onPress: () => captureVision('manual') })),
|
|
423
423
|
children));
|
|
424
424
|
});
|
|
425
|
-
|
|
426
|
-
if (hasVisionCamera) {
|
|
427
|
-
return (react_1.default.createElement(VisionCameraScanner, { ref: ref, onCapture: onCapture, overlayColor: overlayColor, autoCapture: autoCapture, minStableFrames: minStableFrames, enableTorch: enableTorch, quality: quality, useBase64: useBase64, showGrid: showGrid, gridColor: gridColor, gridLineWidth: gridLineWidth, detectionConfig: detectionConfig, onRectangleDetect: onRectangleDetect, showManualCaptureButton: showManualCaptureButton }, children));
|
|
428
|
-
}
|
|
425
|
+
const NativeScanner = (0, react_1.forwardRef)(({ onCapture, overlayColor = DEFAULT_OVERLAY_COLOR, autoCapture = true, minStableFrames = 8, enableTorch = false, quality = 90, useBase64 = false, children, showGrid = true, gridColor, gridLineWidth, detectionConfig, onRectangleDetect, showManualCaptureButton = false, }, ref) => {
|
|
429
426
|
const scannerRef = (0, react_1.useRef)(null);
|
|
430
427
|
const captureResolvers = (0, react_1.useRef)(null);
|
|
431
428
|
const [isAutoCapturing, setIsAutoCapturing] = (0, react_1.useState)(false);
|
|
@@ -701,6 +698,26 @@ exports.DocScanner = (0, react_1.forwardRef)(({ onCapture, overlayColor = DEFAUL
|
|
|
701
698
|
showManualCaptureButton && (react_1.default.createElement(react_native_1.TouchableOpacity, { style: styles.button, onPress: handleManualCapture })),
|
|
702
699
|
children));
|
|
703
700
|
});
|
|
701
|
+
exports.DocScanner = (0, react_1.forwardRef)((props, ref) => {
|
|
702
|
+
(0, react_1.useEffect)(() => {
|
|
703
|
+
if (react_native_1.Platform.OS !== 'android') {
|
|
704
|
+
return;
|
|
705
|
+
}
|
|
706
|
+
if (hasVisionCamera) {
|
|
707
|
+
console.log('[DocScanner] Using VisionCamera pipeline');
|
|
708
|
+
}
|
|
709
|
+
else {
|
|
710
|
+
console.warn('[DocScanner] VisionCamera pipeline unavailable, falling back to native view.', {
|
|
711
|
+
hasVisionCameraModule: Boolean(visionCameraModule),
|
|
712
|
+
hasReanimated: Boolean(reanimatedModule),
|
|
713
|
+
});
|
|
714
|
+
}
|
|
715
|
+
}, []);
|
|
716
|
+
if (hasVisionCamera) {
|
|
717
|
+
return react_1.default.createElement(VisionCameraScanner, { ref: ref, ...props });
|
|
718
|
+
}
|
|
719
|
+
return react_1.default.createElement(NativeScanner, { ref: ref, ...props });
|
|
720
|
+
});
|
|
704
721
|
const styles = react_native_1.StyleSheet.create({
|
|
705
722
|
container: {
|
|
706
723
|
flex: 1,
|
package/package.json
CHANGED
package/src/DocScanner.tsx
CHANGED
|
@@ -611,7 +611,7 @@ const VisionCameraScanner = forwardRef<DocScannerHandle, Props>(
|
|
|
611
611
|
},
|
|
612
612
|
);
|
|
613
613
|
|
|
614
|
-
|
|
614
|
+
const NativeScanner = forwardRef<DocScannerHandle, Props>(
|
|
615
615
|
(
|
|
616
616
|
{
|
|
617
617
|
onCapture,
|
|
@@ -631,29 +631,6 @@ export const DocScanner = forwardRef<DocScannerHandle, Props>(
|
|
|
631
631
|
},
|
|
632
632
|
ref,
|
|
633
633
|
) => {
|
|
634
|
-
if (hasVisionCamera) {
|
|
635
|
-
return (
|
|
636
|
-
<VisionCameraScanner
|
|
637
|
-
ref={ref}
|
|
638
|
-
onCapture={onCapture}
|
|
639
|
-
overlayColor={overlayColor}
|
|
640
|
-
autoCapture={autoCapture}
|
|
641
|
-
minStableFrames={minStableFrames}
|
|
642
|
-
enableTorch={enableTorch}
|
|
643
|
-
quality={quality}
|
|
644
|
-
useBase64={useBase64}
|
|
645
|
-
showGrid={showGrid}
|
|
646
|
-
gridColor={gridColor}
|
|
647
|
-
gridLineWidth={gridLineWidth}
|
|
648
|
-
detectionConfig={detectionConfig}
|
|
649
|
-
onRectangleDetect={onRectangleDetect}
|
|
650
|
-
showManualCaptureButton={showManualCaptureButton}
|
|
651
|
-
>
|
|
652
|
-
{children}
|
|
653
|
-
</VisionCameraScanner>
|
|
654
|
-
);
|
|
655
|
-
}
|
|
656
|
-
|
|
657
634
|
const scannerRef = useRef<any>(null);
|
|
658
635
|
const captureResolvers = useRef<{
|
|
659
636
|
resolve: (value: PictureEvent) => void;
|
|
@@ -1013,6 +990,28 @@ export const DocScanner = forwardRef<DocScannerHandle, Props>(
|
|
|
1013
990
|
},
|
|
1014
991
|
);
|
|
1015
992
|
|
|
993
|
+
export const DocScanner = forwardRef<DocScannerHandle, Props>((props, ref) => {
|
|
994
|
+
useEffect(() => {
|
|
995
|
+
if (Platform.OS !== 'android') {
|
|
996
|
+
return;
|
|
997
|
+
}
|
|
998
|
+
if (hasVisionCamera) {
|
|
999
|
+
console.log('[DocScanner] Using VisionCamera pipeline');
|
|
1000
|
+
} else {
|
|
1001
|
+
console.warn('[DocScanner] VisionCamera pipeline unavailable, falling back to native view.', {
|
|
1002
|
+
hasVisionCameraModule: Boolean(visionCameraModule),
|
|
1003
|
+
hasReanimated: Boolean(reanimatedModule),
|
|
1004
|
+
});
|
|
1005
|
+
}
|
|
1006
|
+
}, []);
|
|
1007
|
+
|
|
1008
|
+
if (hasVisionCamera) {
|
|
1009
|
+
return <VisionCameraScanner ref={ref} {...props} />;
|
|
1010
|
+
}
|
|
1011
|
+
|
|
1012
|
+
return <NativeScanner ref={ref} {...props} />;
|
|
1013
|
+
});
|
|
1014
|
+
|
|
1016
1015
|
const styles = StyleSheet.create({
|
|
1017
1016
|
container: {
|
|
1018
1017
|
flex: 1,
|
/package/android/src/{main → camera2}/kotlin/com/reactnativerectangledocscanner/CameraController.kt
RENAMED
|
File without changes
|
/package/android/src/{main → camera2}/kotlin/com/reactnativerectangledocscanner/CameraView.kt
RENAMED
|
File without changes
|
/package/android/src/{main → camera2}/kotlin/com/reactnativerectangledocscanner/CameraViewManager.kt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
/package/android/src/{main → camera2}/kotlin/com/reactnativerectangledocscanner/ImageProxyExt.kt
RENAMED
|
File without changes
|
/package/android/src/{main → common}/kotlin/com/reactnativerectangledocscanner/DocumentDetector.kt
RENAMED
|
File without changes
|
/package/android/src/{main → common}/kotlin/com/reactnativerectangledocscanner/ImageProcessor.kt
RENAMED
|
File without changes
|