react-native-rectangle-doc-scanner 3.218.0 → 3.220.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.
@@ -157,7 +157,7 @@ class CameraController(
157
157
 
158
158
  val rotation = previewView.display?.rotation ?: Surface.ROTATION_0
159
159
 
160
- // Build Preview with lower resolution to reduce HAL load
160
+ // Build Preview ONLY first
161
161
  preview = Preview.Builder()
162
162
  .setTargetResolution(Size(1280, 720))
163
163
  .setTargetRotation(rotation)
@@ -166,25 +166,53 @@ class CameraController(
166
166
  it.setSurfaceProvider(previewView.surfaceProvider)
167
167
  }
168
168
 
169
- // Build ImageAnalysis with lower resolution
170
- imageAnalysis = ImageAnalysis.Builder()
171
- .setBackpressureStrategy(ImageAnalysis.STRATEGY_KEEP_ONLY_LATEST)
172
- .setTargetRotation(rotation)
173
- .setTargetResolution(Size(1280, 720))
174
- .setOutputImageFormat(ImageAnalysis.OUTPUT_IMAGE_FORMAT_YUV_420_888)
175
- .build()
176
- .also {
177
- it.setAnalyzer(cameraExecutor, DocumentAnalyzer())
178
- }
179
-
180
169
  val cameraSelector = if (useFrontCamera) {
181
170
  CameraSelector.DEFAULT_FRONT_CAMERA
182
171
  } else {
183
172
  CameraSelector.DEFAULT_BACK_CAMERA
184
173
  }
185
174
 
186
- // Bind both Preview and ImageAnalysis together in ONE call
175
+ // Step 1: Bind Preview ONLY first
187
176
  try {
177
+ camera = provider.bindToLifecycle(
178
+ lifecycleOwner,
179
+ cameraSelector,
180
+ preview
181
+ )
182
+ Log.d(TAG, "[CAMERAX-FIX-V5] Preview bound, waiting 2 seconds before adding analysis...")
183
+
184
+ // Step 2: Add ImageAnalysis after a longer delay to let Preview session fully stabilize
185
+ android.os.Handler(android.os.Looper.getMainLooper()).postDelayed({
186
+ bindImageAnalysis(provider, cameraSelector, rotation)
187
+ }, 2000)
188
+
189
+ } catch (e: Exception) {
190
+ Log.e(TAG, "[CAMERAX-FIX-V5] Failed to bind preview", e)
191
+ analysisBound = false
192
+ }
193
+ }
194
+
195
+ private fun bindImageAnalysis(provider: ProcessCameraProvider, cameraSelector: CameraSelector, rotation: Int) {
196
+ if (analysisBound) return
197
+
198
+ Log.d(TAG, "[CAMERAX-FIX-V5] Starting to add ImageAnalysis...")
199
+
200
+ try {
201
+ // Build ImageAnalysis with very low resolution
202
+ imageAnalysis = ImageAnalysis.Builder()
203
+ .setBackpressureStrategy(ImageAnalysis.STRATEGY_KEEP_ONLY_LATEST)
204
+ .setTargetRotation(rotation)
205
+ .setTargetResolution(Size(480, 360))
206
+ .setOutputImageFormat(ImageAnalysis.OUTPUT_IMAGE_FORMAT_YUV_420_888)
207
+ .build()
208
+ .also {
209
+ it.setAnalyzer(cameraExecutor, DocumentAnalyzer())
210
+ }
211
+
212
+ // IMPORTANT: Unbind all first, then rebind together to avoid session reconfiguration timeout
213
+ provider.unbindAll()
214
+
215
+ // Rebind BOTH at the same time
188
216
  camera = provider.bindToLifecycle(
189
217
  lifecycleOwner,
190
218
  cameraSelector,
@@ -192,10 +220,22 @@ class CameraController(
192
220
  imageAnalysis
193
221
  )
194
222
  analysisBound = true
195
- Log.d(TAG, "[CAMERAX-FIX-V3] Camera bound with lower resolution")
223
+ Log.d(TAG, "[CAMERAX-FIX-V5] ImageAnalysis added successfully after unbind/rebind")
196
224
  } catch (e: Exception) {
197
- Log.e(TAG, "[CAMERAX-FIX-V3] Failed to bind camera use cases", e)
225
+ Log.e(TAG, "[CAMERAX-FIX-V5] Failed to add ImageAnalysis", e)
198
226
  analysisBound = false
227
+
228
+ // Fallback: rebind preview only
229
+ try {
230
+ camera = provider.bindToLifecycle(
231
+ lifecycleOwner,
232
+ cameraSelector,
233
+ preview
234
+ )
235
+ Log.d(TAG, "[CAMERAX-FIX-V5] Fallback: Preview only")
236
+ } catch (fallbackException: Exception) {
237
+ Log.e(TAG, "[CAMERAX-FIX-V5] Fallback also failed", fallbackException)
238
+ }
199
239
  }
200
240
  }
201
241
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-rectangle-doc-scanner",
3
- "version": "3.218.0",
3
+ "version": "3.220.0",
4
4
  "description": "Native-backed document scanner for React Native with customizable overlays.",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",