react-native-rectangle-doc-scanner 3.153.0 → 3.155.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.
@@ -41,16 +41,29 @@ class CameraController(
41
41
  useFrontCam: Boolean = false,
42
42
  enableDetection: Boolean = true
43
43
  ) {
44
+ Log.d(TAG, "========================================")
45
+ Log.d(TAG, "[CAMERA_CONTROLLER] startCamera called")
46
+ Log.d(TAG, "[CAMERA_CONTROLLER] useFrontCam: $useFrontCam")
47
+ Log.d(TAG, "[CAMERA_CONTROLLER] enableDetection: $enableDetection")
48
+ Log.d(TAG, "[CAMERA_CONTROLLER] lifecycleOwner: $lifecycleOwner")
49
+ Log.d(TAG, "[CAMERA_CONTROLLER] lifecycleOwner.lifecycle.currentState: ${lifecycleOwner.lifecycle.currentState}")
50
+ Log.d(TAG, "========================================")
51
+
44
52
  this.useFrontCamera = useFrontCam
45
53
 
54
+ Log.d(TAG, "[CAMERA_CONTROLLER] Getting ProcessCameraProvider instance...")
46
55
  val cameraProviderFuture = ProcessCameraProvider.getInstance(context)
47
56
 
48
57
  cameraProviderFuture.addListener({
49
58
  try {
59
+ Log.d(TAG, "[CAMERA_CONTROLLER] ProcessCameraProvider future resolved")
50
60
  cameraProvider = cameraProviderFuture.get()
61
+ Log.d(TAG, "[CAMERA_CONTROLLER] Got cameraProvider: $cameraProvider")
62
+ Log.d(TAG, "[CAMERA_CONTROLLER] Calling bindCameraUseCases...")
51
63
  bindCameraUseCases(enableDetection)
52
64
  } catch (e: Exception) {
53
- Log.e(TAG, "Failed to start camera", e)
65
+ Log.e(TAG, "[CAMERA_CONTROLLER] Failed to start camera", e)
66
+ e.printStackTrace()
54
67
  }
55
68
  }, ContextCompat.getMainExecutor(context))
56
69
  }
@@ -67,12 +80,20 @@ class CameraController(
67
80
  * Bind camera use cases (preview, capture, analysis)
68
81
  */
69
82
  private fun bindCameraUseCases(enableDetection: Boolean) {
70
- val cameraProvider = cameraProvider ?: return
83
+ Log.d(TAG, "[BIND] bindCameraUseCases called")
84
+ Log.d(TAG, "[BIND] enableDetection: $enableDetection")
85
+
86
+ val cameraProvider = cameraProvider
87
+ if (cameraProvider == null) {
88
+ Log.e(TAG, "[BIND] cameraProvider is null, returning")
89
+ return
90
+ }
71
91
 
72
92
  // Check lifecycle state
73
93
  val lifecycle = lifecycleOwner.lifecycle
94
+ Log.d(TAG, "[BIND] Lifecycle current state: ${lifecycle.currentState}")
74
95
  if (lifecycle.currentState == Lifecycle.State.DESTROYED) {
75
- Log.e(TAG, "Cannot bind camera - lifecycle is destroyed")
96
+ Log.e(TAG, "[BIND] Cannot bind camera - lifecycle is destroyed")
76
97
  return
77
98
  }
78
99
 
@@ -82,21 +103,27 @@ class CameraController(
82
103
  } else {
83
104
  CameraSelector.DEFAULT_BACK_CAMERA
84
105
  }
106
+ Log.d(TAG, "[BIND] Camera selector: ${if (useFrontCamera) "FRONT" else "BACK"}")
85
107
 
86
108
  // Preview use case
109
+ Log.d(TAG, "[BIND] Creating Preview use case...")
87
110
  val preview = Preview.Builder()
88
111
  .setTargetResolution(Size(1080, 1920))
89
112
  .build()
113
+ Log.d(TAG, "[BIND] Preview created: $preview")
90
114
 
91
115
  // Image capture use case (high resolution for document scanning)
116
+ Log.d(TAG, "[BIND] Creating ImageCapture use case...")
92
117
  imageCapture = ImageCapture.Builder()
93
118
  .setCaptureMode(ImageCapture.CAPTURE_MODE_MAXIMIZE_QUALITY)
94
119
  .setTargetResolution(Size(1920, 2560))
95
120
  .setFlashMode(ImageCapture.FLASH_MODE_AUTO)
96
121
  .build()
122
+ Log.d(TAG, "[BIND] ImageCapture created: $imageCapture")
97
123
 
98
124
  // Image analysis use case for rectangle detection
99
125
  imageAnalysis = if (enableDetection) {
126
+ Log.d(TAG, "[BIND] Creating ImageAnalysis use case...")
100
127
  ImageAnalysis.Builder()
101
128
  .setTargetResolution(Size(720, 1280))
102
129
  .setBackpressureStrategy(ImageAnalysis.STRATEGY_KEEP_ONLY_LATEST)
@@ -106,13 +133,16 @@ class CameraController(
106
133
  analysis.setAnalyzer(cameraExecutor) { imageProxy ->
107
134
  analyzeFrame(imageProxy)
108
135
  }
136
+ Log.d(TAG, "[BIND] ImageAnalysis created and analyzer set: $analysis")
109
137
  }
110
138
  } else {
139
+ Log.d(TAG, "[BIND] ImageAnalysis disabled")
111
140
  null
112
141
  }
113
142
 
114
143
  try {
115
144
  // Unbind all use cases before rebinding
145
+ Log.d(TAG, "[BIND] Unbinding all existing use cases...")
116
146
  cameraProvider.unbindAll()
117
147
 
118
148
  // Bind use cases to camera
@@ -120,24 +150,36 @@ class CameraController(
120
150
  if (imageAnalysis != null) {
121
151
  useCases.add(imageAnalysis!!)
122
152
  }
153
+ Log.d(TAG, "[BIND] Total use cases to bind: ${useCases.size}")
123
154
 
155
+ Log.d(TAG, "[BIND] Binding to lifecycle...")
124
156
  camera = cameraProvider.bindToLifecycle(
125
157
  lifecycleOwner,
126
158
  cameraSelector,
127
159
  *useCases.toTypedArray()
128
160
  )
161
+ Log.d(TAG, "[BIND] Bound to lifecycle successfully, camera: $camera")
129
162
 
130
163
  // Set surface provider AFTER binding to lifecycle
164
+ Log.d(TAG, "[BIND] Setting surface provider to previewView...")
165
+ Log.d(TAG, "[BIND] PreviewView: $previewView")
166
+ Log.d(TAG, "[BIND] PreviewView.surfaceProvider: ${previewView.surfaceProvider}")
131
167
  preview.setSurfaceProvider(previewView.surfaceProvider)
168
+ Log.d(TAG, "[BIND] Surface provider set successfully")
132
169
 
133
170
  // Restore torch state if it was enabled
134
171
  if (torchEnabled) {
172
+ Log.d(TAG, "[BIND] Restoring torch state...")
135
173
  setTorchEnabled(true)
136
174
  }
137
175
 
138
- Log.d(TAG, "Camera started successfully, hasFlashUnit: ${camera?.cameraInfo?.hasFlashUnit()}")
176
+ Log.d(TAG, "[BIND] ========================================")
177
+ Log.d(TAG, "[BIND] Camera started successfully!")
178
+ Log.d(TAG, "[BIND] hasFlashUnit: ${camera?.cameraInfo?.hasFlashUnit()}")
179
+ Log.d(TAG, "[BIND] ========================================")
139
180
  } catch (e: Exception) {
140
- Log.e(TAG, "Failed to bind camera use cases", e)
181
+ Log.e(TAG, "[BIND] Failed to bind camera use cases", e)
182
+ e.printStackTrace()
141
183
  }
142
184
  }
143
185
 
@@ -80,10 +80,16 @@ class DocumentScannerView(context: ThemedReactContext) : FrameLayout(context), L
80
80
 
81
81
  override fun onAttachedToWindow() {
82
82
  super.onAttachedToWindow()
83
+ Log.d(TAG, "========================================")
83
84
  Log.d(TAG, "onAttachedToWindow called")
85
+ Log.d(TAG, "Current lifecycle state: ${lifecycleRegistry.currentState}")
86
+ Log.d(TAG, "PreviewView: width=${previewView.width}, height=${previewView.height}")
87
+ Log.d(TAG, "This view: width=$width, height=$height")
88
+ Log.d(TAG, "========================================")
84
89
 
85
90
  // Setup and start camera when view is attached
86
91
  post {
92
+ Log.d(TAG, "[POST] Starting camera setup...")
87
93
  setupCamera()
88
94
  startCamera()
89
95
  }
@@ -91,15 +97,24 @@ class DocumentScannerView(context: ThemedReactContext) : FrameLayout(context), L
91
97
 
92
98
  private fun setupCamera() {
93
99
  try {
100
+ Log.d(TAG, "[SETUP] Creating CameraController...")
101
+ Log.d(TAG, "[SETUP] Context: $context")
102
+ Log.d(TAG, "[SETUP] LifecycleOwner: $this")
103
+ Log.d(TAG, "[SETUP] PreviewView: $previewView")
104
+
94
105
  cameraController = CameraController(context, this, previewView)
106
+
107
+ Log.d(TAG, "[SETUP] CameraController created: $cameraController")
108
+
95
109
  cameraController?.onFrameAnalyzed = { rectangle, imageWidth, imageHeight ->
96
110
  handleDetectionResult(rectangle, imageWidth, imageHeight)
97
111
  }
98
112
  lastDetectionTimestamp = 0L
99
113
 
100
- Log.d(TAG, "Camera setup completed")
114
+ Log.d(TAG, "[SETUP] Camera setup completed successfully")
101
115
  } catch (e: Exception) {
102
- Log.e(TAG, "Failed to setup camera", e)
116
+ Log.e(TAG, "[SETUP] Failed to setup camera", e)
117
+ e.printStackTrace()
103
118
  }
104
119
  }
105
120
 
@@ -354,29 +369,51 @@ class DocumentScannerView(context: ThemedReactContext) : FrameLayout(context), L
354
369
  }
355
370
 
356
371
  fun startCamera() {
372
+ Log.d(TAG, "[START_CAMERA] Starting camera...")
373
+ Log.d(TAG, "[START_CAMERA] Current lifecycle state: ${lifecycleRegistry.currentState}")
374
+ Log.d(TAG, "[START_CAMERA] isUsingFrontCamera: $isUsingFrontCamera")
375
+ Log.d(TAG, "[START_CAMERA] isTorchEnabled: $isTorchEnabled")
376
+ Log.d(TAG, "[START_CAMERA] CameraController: $cameraController")
377
+
357
378
  lastDetectionTimestamp = 0L
358
379
  cameraController?.onFrameAnalyzed = { rectangle, imageWidth, imageHeight ->
359
380
  handleDetectionResult(rectangle, imageWidth, imageHeight)
360
381
  }
361
382
 
362
383
  // Transition lifecycle states properly
384
+ val previousState = lifecycleRegistry.currentState
363
385
  when (lifecycleRegistry.currentState) {
364
386
  Lifecycle.State.CREATED -> {
387
+ Log.d(TAG, "[START_CAMERA] Transitioning CREATED -> STARTED")
365
388
  lifecycleRegistry.currentState = Lifecycle.State.STARTED
389
+ Log.d(TAG, "[START_CAMERA] Transitioning STARTED -> RESUMED")
366
390
  lifecycleRegistry.currentState = Lifecycle.State.RESUMED
367
391
  }
368
392
  Lifecycle.State.STARTED -> {
393
+ Log.d(TAG, "[START_CAMERA] Transitioning STARTED -> RESUMED")
369
394
  lifecycleRegistry.currentState = Lifecycle.State.RESUMED
370
395
  }
371
396
  else -> {
372
- // Already RESUMED or destroyed
397
+ Log.d(TAG, "[START_CAMERA] Already in state: ${lifecycleRegistry.currentState}")
373
398
  }
374
399
  }
400
+ Log.d(TAG, "[START_CAMERA] Lifecycle transitioned: $previousState -> ${lifecycleRegistry.currentState}")
401
+
402
+ Log.d(TAG, "[START_CAMERA] Calling CameraController.startCamera()...")
403
+ try {
404
+ cameraController?.startCamera(isUsingFrontCamera, true)
405
+ Log.d(TAG, "[START_CAMERA] CameraController.startCamera() completed")
406
+ } catch (e: Exception) {
407
+ Log.e(TAG, "[START_CAMERA] Failed to start camera", e)
408
+ e.printStackTrace()
409
+ }
375
410
 
376
- cameraController?.startCamera(isUsingFrontCamera, true)
377
411
  if (isTorchEnabled) {
412
+ Log.d(TAG, "[START_CAMERA] Enabling torch...")
378
413
  cameraController?.setTorchEnabled(true)
379
414
  }
415
+
416
+ Log.d(TAG, "[START_CAMERA] Camera start completed")
380
417
  }
381
418
 
382
419
  fun stopCamera() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-rectangle-doc-scanner",
3
- "version": "3.153.0",
3
+ "version": "3.155.0",
4
4
  "description": "Native-backed document scanner for React Native with customizable overlays.",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",