react-native-rectangle-doc-scanner 3.212.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
@@ -48,8 +49,6 @@ class CameraController(
48
49
 
49
50
  companion object {
50
51
  private const val TAG = "CameraController"
51
- private const val ANALYSIS_WIDTH = 1280
52
- private const val ANALYSIS_HEIGHT = 720
53
52
  }
54
53
 
55
54
  private data class LastFrame(
@@ -90,6 +89,7 @@ class CameraController(
90
89
  fun stopCamera() {
91
90
  Log.d(TAG, "[CAMERAX] stopCamera called")
92
91
  cameraProvider?.unbindAll()
92
+ analysisBound = false
93
93
  }
94
94
 
95
95
  fun capturePhoto(
@@ -153,31 +153,56 @@ class CameraController(
153
153
  private fun bindCameraUseCases() {
154
154
  val provider = cameraProvider ?: return
155
155
  provider.unbindAll()
156
+ analysisBound = false
156
157
 
157
158
  val rotation = previewView.display?.rotation ?: Surface.ROTATION_0
158
159
  preview = Preview.Builder()
160
+ .setTargetAspectRatio(AspectRatio.RATIO_4_3)
159
161
  .setTargetRotation(rotation)
160
162
  .build()
161
163
  .also {
162
164
  it.setSurfaceProvider(previewView.surfaceProvider)
163
165
  }
164
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
165
196
  imageAnalysis = ImageAnalysis.Builder()
166
197
  .setBackpressureStrategy(ImageAnalysis.STRATEGY_KEEP_ONLY_LATEST)
167
- .setTargetResolution(Size(ANALYSIS_WIDTH, ANALYSIS_HEIGHT))
168
198
  .setTargetRotation(rotation)
199
+ .setTargetAspectRatio(AspectRatio.RATIO_4_3)
169
200
  .setOutputImageFormat(ImageAnalysis.OUTPUT_IMAGE_FORMAT_YUV_420_888)
170
201
  .build()
171
202
  .also {
172
203
  it.setAnalyzer(cameraExecutor, DocumentAnalyzer())
173
204
  }
174
205
 
175
- val cameraSelector = if (useFrontCamera) {
176
- CameraSelector.DEFAULT_FRONT_CAMERA
177
- } else {
178
- CameraSelector.DEFAULT_BACK_CAMERA
179
- }
180
-
181
206
  try {
182
207
  camera = provider.bindToLifecycle(
183
208
  lifecycleOwner,
@@ -185,9 +210,11 @@ class CameraController(
185
210
  preview,
186
211
  imageAnalysis
187
212
  )
188
- Log.d(TAG, "[CAMERAX] Camera bound successfully")
213
+ analysisBound = true
214
+ Log.d(TAG, "[CAMERAX] Analysis bound successfully")
189
215
  } catch (e: Exception) {
190
- Log.e(TAG, "[CAMERAX] Failed to bind camera", e)
216
+ Log.e(TAG, "[CAMERAX] Failed to bind analysis; keeping preview only", e)
217
+ analysisBound = false
191
218
  }
192
219
  }
193
220
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-rectangle-doc-scanner",
3
- "version": "3.212.0",
3
+ "version": "3.214.0",
4
4
  "description": "Native-backed document scanner for React Native with customizable overlays.",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",