react-native-rectangle-doc-scanner 3.192.0 → 3.193.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.
|
@@ -11,6 +11,8 @@ import androidx.camera.view.PreviewView
|
|
|
11
11
|
import androidx.core.content.ContextCompat
|
|
12
12
|
import androidx.lifecycle.Lifecycle
|
|
13
13
|
import androidx.lifecycle.LifecycleOwner
|
|
14
|
+
import androidx.lifecycle.LiveData
|
|
15
|
+
import androidx.lifecycle.Observer
|
|
14
16
|
import java.io.File
|
|
15
17
|
import java.util.concurrent.ExecutorService
|
|
16
18
|
import java.util.concurrent.Executors
|
|
@@ -30,6 +32,9 @@ class CameraController(
|
|
|
30
32
|
private var torchEnabled = false
|
|
31
33
|
private var detectionEnabled = true
|
|
32
34
|
private var isCaptureSession = false
|
|
35
|
+
private var hasFallbackAttempted = false
|
|
36
|
+
private var cameraStateLiveData: LiveData<CameraState>? = null
|
|
37
|
+
private var cameraStateObserver: Observer<CameraState>? = null
|
|
33
38
|
|
|
34
39
|
var onFrameAnalyzed: ((Rectangle?, Int, Int) -> Unit)? = null
|
|
35
40
|
|
|
@@ -192,6 +197,7 @@ class CameraController(
|
|
|
192
197
|
*useCases.toTypedArray()
|
|
193
198
|
)
|
|
194
199
|
Log.d(TAG, "[BIND] Bound to lifecycle successfully, camera: $camera")
|
|
200
|
+
registerCameraStateObserver(camera)
|
|
195
201
|
|
|
196
202
|
// Restore torch state if it was enabled
|
|
197
203
|
if (torchEnabled) {
|
|
@@ -210,6 +216,31 @@ class CameraController(
|
|
|
210
216
|
}
|
|
211
217
|
}
|
|
212
218
|
|
|
219
|
+
private fun registerCameraStateObserver(camera: Camera?) {
|
|
220
|
+
val cam = camera ?: return
|
|
221
|
+
cameraStateLiveData?.let { liveData ->
|
|
222
|
+
cameraStateObserver?.let { liveData.removeObserver(it) }
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
val observer = Observer<CameraState> { state ->
|
|
226
|
+
val error = state.error
|
|
227
|
+
if (error != null && !hasFallbackAttempted && !isCaptureSession) {
|
|
228
|
+
hasFallbackAttempted = true
|
|
229
|
+
Log.e(TAG, "[STATE] Camera error detected (${error.code}), falling back to preview-only")
|
|
230
|
+
try {
|
|
231
|
+
cameraProvider?.unbindAll()
|
|
232
|
+
bindCameraUseCases(enableDetection = false, useImageCapture = false)
|
|
233
|
+
} catch (e: Exception) {
|
|
234
|
+
Log.e(TAG, "[STATE] Fallback bind failed", e)
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
cameraStateObserver = observer
|
|
240
|
+
cameraStateLiveData = cam.cameraInfo.cameraState
|
|
241
|
+
cam.cameraInfo.cameraState.observe(lifecycleOwner, observer)
|
|
242
|
+
}
|
|
243
|
+
|
|
213
244
|
/**
|
|
214
245
|
* Analyze frame for rectangle detection
|
|
215
246
|
*/
|
package/package.json
CHANGED