react-native-rectangle-doc-scanner 3.150.0 → 3.152.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.
|
@@ -62,7 +62,7 @@ class CameraView(context: Context) : FrameLayout(context), LifecycleOwner {
|
|
|
62
62
|
addView(overlayView)
|
|
63
63
|
|
|
64
64
|
Log.d(TAG, "CameraView initialized")
|
|
65
|
-
lifecycleRegistry.
|
|
65
|
+
lifecycleRegistry.handleLifecycleEvent(Lifecycle.Event.ON_CREATE)
|
|
66
66
|
}
|
|
67
67
|
|
|
68
68
|
/**
|
|
@@ -91,7 +91,8 @@ class CameraView(context: Context) : FrameLayout(context), LifecycleOwner {
|
|
|
91
91
|
fun stopCamera() {
|
|
92
92
|
cameraProvider?.unbindAll()
|
|
93
93
|
if (lifecycleRegistry.currentState != Lifecycle.State.DESTROYED) {
|
|
94
|
-
lifecycleRegistry.
|
|
94
|
+
lifecycleRegistry.handleLifecycleEvent(Lifecycle.Event.ON_PAUSE)
|
|
95
|
+
lifecycleRegistry.handleLifecycleEvent(Lifecycle.Event.ON_STOP)
|
|
95
96
|
}
|
|
96
97
|
}
|
|
97
98
|
|
|
@@ -115,6 +116,11 @@ class CameraView(context: Context) : FrameLayout(context), LifecycleOwner {
|
|
|
115
116
|
// Unbind all before rebinding
|
|
116
117
|
provider.unbindAll()
|
|
117
118
|
|
|
119
|
+
if (lifecycleRegistry.currentState != Lifecycle.State.DESTROYED) {
|
|
120
|
+
lifecycleRegistry.handleLifecycleEvent(Lifecycle.Event.ON_START)
|
|
121
|
+
lifecycleRegistry.handleLifecycleEvent(Lifecycle.Event.ON_RESUME)
|
|
122
|
+
}
|
|
123
|
+
|
|
118
124
|
// Preview use case
|
|
119
125
|
preview = Preview.Builder()
|
|
120
126
|
.build()
|
|
@@ -222,7 +228,7 @@ class CameraView(context: Context) : FrameLayout(context), LifecycleOwner {
|
|
|
222
228
|
override fun onDetachedFromWindow() {
|
|
223
229
|
super.onDetachedFromWindow()
|
|
224
230
|
stopCamera()
|
|
225
|
-
lifecycleRegistry.
|
|
231
|
+
lifecycleRegistry.handleLifecycleEvent(Lifecycle.Event.ON_DESTROY)
|
|
226
232
|
if (!cameraExecutor.isShutdown) {
|
|
227
233
|
cameraExecutor.shutdown()
|
|
228
234
|
}
|
|
@@ -77,19 +77,27 @@ class DocumentScannerView(context: ThemedReactContext) : FrameLayout(context), L
|
|
|
77
77
|
setupCamera()
|
|
78
78
|
}
|
|
79
79
|
|
|
80
|
-
lifecycleRegistry.
|
|
80
|
+
lifecycleRegistry.handleLifecycleEvent(Lifecycle.Event.ON_CREATE)
|
|
81
81
|
}
|
|
82
82
|
|
|
83
83
|
private fun setupCamera() {
|
|
84
84
|
try {
|
|
85
|
+
// Move to STARTED state first
|
|
86
|
+
if (lifecycleRegistry.currentState != Lifecycle.State.DESTROYED) {
|
|
87
|
+
lifecycleRegistry.handleLifecycleEvent(Lifecycle.Event.ON_START)
|
|
88
|
+
}
|
|
89
|
+
|
|
85
90
|
cameraController = CameraController(context, this, previewView)
|
|
86
91
|
cameraController?.onFrameAnalyzed = { rectangle, imageWidth, imageHeight ->
|
|
87
92
|
handleDetectionResult(rectangle, imageWidth, imageHeight)
|
|
88
93
|
}
|
|
89
94
|
lastDetectionTimestamp = 0L
|
|
95
|
+
|
|
96
|
+
// Move to RESUMED state before starting camera
|
|
90
97
|
if (lifecycleRegistry.currentState != Lifecycle.State.DESTROYED) {
|
|
91
|
-
lifecycleRegistry.
|
|
98
|
+
lifecycleRegistry.handleLifecycleEvent(Lifecycle.Event.ON_RESUME)
|
|
92
99
|
}
|
|
100
|
+
|
|
93
101
|
cameraController?.startCamera(isUsingFrontCamera, true)
|
|
94
102
|
if (isTorchEnabled) {
|
|
95
103
|
cameraController?.setTorchEnabled(true)
|
|
@@ -98,7 +106,7 @@ class DocumentScannerView(context: ThemedReactContext) : FrameLayout(context), L
|
|
|
98
106
|
Log.d(TAG, "Camera setup completed")
|
|
99
107
|
} catch (e: Exception) {
|
|
100
108
|
Log.e(TAG, "Failed to setup camera", e)
|
|
101
|
-
lifecycleRegistry.
|
|
109
|
+
lifecycleRegistry.handleLifecycleEvent(Lifecycle.Event.ON_CREATE)
|
|
102
110
|
}
|
|
103
111
|
}
|
|
104
112
|
|
|
@@ -357,11 +365,20 @@ class DocumentScannerView(context: ThemedReactContext) : FrameLayout(context), L
|
|
|
357
365
|
cameraController?.onFrameAnalyzed = { rectangle, imageWidth, imageHeight ->
|
|
358
366
|
handleDetectionResult(rectangle, imageWidth, imageHeight)
|
|
359
367
|
}
|
|
368
|
+
|
|
369
|
+
// Ensure proper lifecycle state before starting camera
|
|
370
|
+
if (lifecycleRegistry.currentState == Lifecycle.State.CREATED) {
|
|
371
|
+
lifecycleRegistry.currentState = Lifecycle.State.STARTED
|
|
372
|
+
}
|
|
373
|
+
if (lifecycleRegistry.currentState != Lifecycle.State.DESTROYED) {
|
|
374
|
+
lifecycleRegistry.handleLifecycleEvent(Lifecycle.Event.ON_START)
|
|
375
|
+
lifecycleRegistry.handleLifecycleEvent(Lifecycle.Event.ON_RESUME)
|
|
376
|
+
}
|
|
377
|
+
|
|
360
378
|
cameraController?.startCamera(isUsingFrontCamera, true)
|
|
361
379
|
if (isTorchEnabled) {
|
|
362
380
|
cameraController?.setTorchEnabled(true)
|
|
363
381
|
}
|
|
364
|
-
lifecycleRegistry.currentState = Lifecycle.State.RESUMED
|
|
365
382
|
}
|
|
366
383
|
|
|
367
384
|
fun stopCamera() {
|
|
@@ -369,9 +386,10 @@ class DocumentScannerView(context: ThemedReactContext) : FrameLayout(context), L
|
|
|
369
386
|
cameraController?.stopCamera()
|
|
370
387
|
overlayView.setRectangle(null, overlayColor)
|
|
371
388
|
stableCounter = 0
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
389
|
+
if (lifecycleRegistry.currentState != Lifecycle.State.DESTROYED) {
|
|
390
|
+
lifecycleRegistry.handleLifecycleEvent(Lifecycle.Event.ON_PAUSE)
|
|
391
|
+
lifecycleRegistry.handleLifecycleEvent(Lifecycle.Event.ON_STOP)
|
|
392
|
+
}
|
|
375
393
|
} else {
|
|
376
394
|
Log.d(TAG, "Cannot stop camera while capturing")
|
|
377
395
|
}
|
|
@@ -404,7 +422,7 @@ class DocumentScannerView(context: ThemedReactContext) : FrameLayout(context), L
|
|
|
404
422
|
private fun performCleanup() {
|
|
405
423
|
Log.d(TAG, "Performing cleanup")
|
|
406
424
|
cameraController?.stopCamera()
|
|
407
|
-
lifecycleRegistry.
|
|
425
|
+
lifecycleRegistry.handleLifecycleEvent(Lifecycle.Event.ON_DESTROY)
|
|
408
426
|
cameraController?.shutdown()
|
|
409
427
|
scope.cancel()
|
|
410
428
|
}
|
package/package.json
CHANGED