react-native-rectangle-doc-scanner 3.213.0 → 3.214.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.
|
@@ -40,6 +40,7 @@ class CameraController(
|
|
|
40
40
|
private var camera: Camera? = null
|
|
41
41
|
private val cameraExecutor: ExecutorService = Executors.newSingleThreadExecutor()
|
|
42
42
|
private val lastFrame = AtomicReference<LastFrame?>()
|
|
43
|
+
private var analysisBound = false
|
|
43
44
|
|
|
44
45
|
private var useFrontCamera = false
|
|
45
46
|
private var detectionEnabled = true
|
|
@@ -88,6 +89,7 @@ class CameraController(
|
|
|
88
89
|
fun stopCamera() {
|
|
89
90
|
Log.d(TAG, "[CAMERAX] stopCamera called")
|
|
90
91
|
cameraProvider?.unbindAll()
|
|
92
|
+
analysisBound = false
|
|
91
93
|
}
|
|
92
94
|
|
|
93
95
|
fun capturePhoto(
|
|
@@ -151,6 +153,7 @@ class CameraController(
|
|
|
151
153
|
private fun bindCameraUseCases() {
|
|
152
154
|
val provider = cameraProvider ?: return
|
|
153
155
|
provider.unbindAll()
|
|
156
|
+
analysisBound = false
|
|
154
157
|
|
|
155
158
|
val rotation = previewView.display?.rotation ?: Surface.ROTATION_0
|
|
156
159
|
preview = Preview.Builder()
|
|
@@ -161,6 +164,35 @@ class CameraController(
|
|
|
161
164
|
it.setSurfaceProvider(previewView.surfaceProvider)
|
|
162
165
|
}
|
|
163
166
|
|
|
167
|
+
val cameraSelector = if (useFrontCamera) {
|
|
168
|
+
CameraSelector.DEFAULT_FRONT_CAMERA
|
|
169
|
+
} else {
|
|
170
|
+
CameraSelector.DEFAULT_BACK_CAMERA
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
try {
|
|
174
|
+
camera = provider.bindToLifecycle(
|
|
175
|
+
lifecycleOwner,
|
|
176
|
+
cameraSelector,
|
|
177
|
+
preview
|
|
178
|
+
)
|
|
179
|
+
Log.d(TAG, "[CAMERAX] Camera bound successfully")
|
|
180
|
+
} catch (e: Exception) {
|
|
181
|
+
Log.e(TAG, "[CAMERAX] Failed to bind camera", e)
|
|
182
|
+
return
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
// Bind analysis after preview to avoid session timeouts on some devices.
|
|
186
|
+
ContextCompat.getMainExecutor(context).execute {
|
|
187
|
+
bindAnalysis(cameraSelector, rotation)
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
private fun bindAnalysis(cameraSelector: CameraSelector, rotation: Int) {
|
|
192
|
+
if (analysisBound) {
|
|
193
|
+
return
|
|
194
|
+
}
|
|
195
|
+
val provider = cameraProvider ?: return
|
|
164
196
|
imageAnalysis = ImageAnalysis.Builder()
|
|
165
197
|
.setBackpressureStrategy(ImageAnalysis.STRATEGY_KEEP_ONLY_LATEST)
|
|
166
198
|
.setTargetRotation(rotation)
|
|
@@ -171,12 +203,6 @@ class CameraController(
|
|
|
171
203
|
it.setAnalyzer(cameraExecutor, DocumentAnalyzer())
|
|
172
204
|
}
|
|
173
205
|
|
|
174
|
-
val cameraSelector = if (useFrontCamera) {
|
|
175
|
-
CameraSelector.DEFAULT_FRONT_CAMERA
|
|
176
|
-
} else {
|
|
177
|
-
CameraSelector.DEFAULT_BACK_CAMERA
|
|
178
|
-
}
|
|
179
|
-
|
|
180
206
|
try {
|
|
181
207
|
camera = provider.bindToLifecycle(
|
|
182
208
|
lifecycleOwner,
|
|
@@ -184,9 +210,11 @@ class CameraController(
|
|
|
184
210
|
preview,
|
|
185
211
|
imageAnalysis
|
|
186
212
|
)
|
|
187
|
-
|
|
213
|
+
analysisBound = true
|
|
214
|
+
Log.d(TAG, "[CAMERAX] Analysis bound successfully")
|
|
188
215
|
} catch (e: Exception) {
|
|
189
|
-
Log.e(TAG, "[CAMERAX] Failed to bind
|
|
216
|
+
Log.e(TAG, "[CAMERAX] Failed to bind analysis; keeping preview only", e)
|
|
217
|
+
analysisBound = false
|
|
190
218
|
}
|
|
191
219
|
}
|
|
192
220
|
|
package/package.json
CHANGED