react-native-rectangle-doc-scanner 3.154.0 → 3.156.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
 
@@ -61,29 +61,59 @@ class DocumentScannerView(context: ThemedReactContext) : FrameLayout(context), L
61
61
  override fun getLifecycle(): Lifecycle = lifecycleRegistry
62
62
 
63
63
  init {
64
+ Log.d(TAG, "╔════════════════════════════════════════╗")
65
+ Log.d(TAG, "║ DocumentScannerView INIT START ║")
66
+ Log.d(TAG, "╚════════════════════════════════════════╝")
67
+ Log.d(TAG, "[INIT] Context: $context")
68
+ Log.d(TAG, "[INIT] Context class: ${context.javaClass.name}")
69
+
64
70
  // Initialize lifecycle FIRST
71
+ Log.d(TAG, "[INIT] Setting lifecycle to INITIALIZED...")
65
72
  lifecycleRegistry.currentState = Lifecycle.State.INITIALIZED
73
+ Log.d(TAG, "[INIT] Lifecycle state: ${lifecycleRegistry.currentState}")
66
74
 
67
75
  // Create preview view
76
+ Log.d(TAG, "[INIT] Creating PreviewView...")
68
77
  previewView = PreviewView(context).apply {
69
78
  layoutParams = LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)
70
79
  scaleType = PreviewView.ScaleType.FILL_CENTER
71
80
  }
81
+ Log.d(TAG, "[INIT] PreviewView created: $previewView")
82
+
83
+ Log.d(TAG, "[INIT] Adding PreviewView to parent...")
72
84
  addView(previewView)
85
+ Log.d(TAG, "[INIT] PreviewView added, childCount: $childCount")
73
86
 
74
87
  // Create overlay view for drawing rectangle
88
+ Log.d(TAG, "[INIT] Creating OverlayView...")
75
89
  overlayView = OverlayView(context)
90
+ Log.d(TAG, "[INIT] OverlayView created: $overlayView")
91
+
92
+ Log.d(TAG, "[INIT] Adding OverlayView to parent...")
76
93
  addView(overlayView)
94
+ Log.d(TAG, "[INIT] OverlayView added, childCount: $childCount")
77
95
 
96
+ Log.d(TAG, "[INIT] Setting lifecycle to CREATED...")
78
97
  lifecycleRegistry.currentState = Lifecycle.State.CREATED
98
+ Log.d(TAG, "[INIT] Lifecycle state: ${lifecycleRegistry.currentState}")
99
+
100
+ Log.d(TAG, "╔════════════════════════════════════════╗")
101
+ Log.d(TAG, "║ DocumentScannerView INIT COMPLETE ║")
102
+ Log.d(TAG, "╚════════════════════════════════════════╝")
79
103
  }
80
104
 
81
105
  override fun onAttachedToWindow() {
82
106
  super.onAttachedToWindow()
107
+ Log.d(TAG, "========================================")
83
108
  Log.d(TAG, "onAttachedToWindow called")
109
+ Log.d(TAG, "Current lifecycle state: ${lifecycleRegistry.currentState}")
110
+ Log.d(TAG, "PreviewView: width=${previewView.width}, height=${previewView.height}")
111
+ Log.d(TAG, "This view: width=$width, height=$height")
112
+ Log.d(TAG, "========================================")
84
113
 
85
114
  // Setup and start camera when view is attached
86
115
  post {
116
+ Log.d(TAG, "[POST] Starting camera setup...")
87
117
  setupCamera()
88
118
  startCamera()
89
119
  }
@@ -91,15 +121,24 @@ class DocumentScannerView(context: ThemedReactContext) : FrameLayout(context), L
91
121
 
92
122
  private fun setupCamera() {
93
123
  try {
124
+ Log.d(TAG, "[SETUP] Creating CameraController...")
125
+ Log.d(TAG, "[SETUP] Context: $context")
126
+ Log.d(TAG, "[SETUP] LifecycleOwner: $this")
127
+ Log.d(TAG, "[SETUP] PreviewView: $previewView")
128
+
94
129
  cameraController = CameraController(context, this, previewView)
130
+
131
+ Log.d(TAG, "[SETUP] CameraController created: $cameraController")
132
+
95
133
  cameraController?.onFrameAnalyzed = { rectangle, imageWidth, imageHeight ->
96
134
  handleDetectionResult(rectangle, imageWidth, imageHeight)
97
135
  }
98
136
  lastDetectionTimestamp = 0L
99
137
 
100
- Log.d(TAG, "Camera setup completed")
138
+ Log.d(TAG, "[SETUP] Camera setup completed successfully")
101
139
  } catch (e: Exception) {
102
- Log.e(TAG, "Failed to setup camera", e)
140
+ Log.e(TAG, "[SETUP] Failed to setup camera", e)
141
+ e.printStackTrace()
103
142
  }
104
143
  }
105
144
 
@@ -354,29 +393,51 @@ class DocumentScannerView(context: ThemedReactContext) : FrameLayout(context), L
354
393
  }
355
394
 
356
395
  fun startCamera() {
396
+ Log.d(TAG, "[START_CAMERA] Starting camera...")
397
+ Log.d(TAG, "[START_CAMERA] Current lifecycle state: ${lifecycleRegistry.currentState}")
398
+ Log.d(TAG, "[START_CAMERA] isUsingFrontCamera: $isUsingFrontCamera")
399
+ Log.d(TAG, "[START_CAMERA] isTorchEnabled: $isTorchEnabled")
400
+ Log.d(TAG, "[START_CAMERA] CameraController: $cameraController")
401
+
357
402
  lastDetectionTimestamp = 0L
358
403
  cameraController?.onFrameAnalyzed = { rectangle, imageWidth, imageHeight ->
359
404
  handleDetectionResult(rectangle, imageWidth, imageHeight)
360
405
  }
361
406
 
362
407
  // Transition lifecycle states properly
408
+ val previousState = lifecycleRegistry.currentState
363
409
  when (lifecycleRegistry.currentState) {
364
410
  Lifecycle.State.CREATED -> {
411
+ Log.d(TAG, "[START_CAMERA] Transitioning CREATED -> STARTED")
365
412
  lifecycleRegistry.currentState = Lifecycle.State.STARTED
413
+ Log.d(TAG, "[START_CAMERA] Transitioning STARTED -> RESUMED")
366
414
  lifecycleRegistry.currentState = Lifecycle.State.RESUMED
367
415
  }
368
416
  Lifecycle.State.STARTED -> {
417
+ Log.d(TAG, "[START_CAMERA] Transitioning STARTED -> RESUMED")
369
418
  lifecycleRegistry.currentState = Lifecycle.State.RESUMED
370
419
  }
371
420
  else -> {
372
- // Already RESUMED or destroyed
421
+ Log.d(TAG, "[START_CAMERA] Already in state: ${lifecycleRegistry.currentState}")
373
422
  }
374
423
  }
424
+ Log.d(TAG, "[START_CAMERA] Lifecycle transitioned: $previousState -> ${lifecycleRegistry.currentState}")
425
+
426
+ Log.d(TAG, "[START_CAMERA] Calling CameraController.startCamera()...")
427
+ try {
428
+ cameraController?.startCamera(isUsingFrontCamera, true)
429
+ Log.d(TAG, "[START_CAMERA] CameraController.startCamera() completed")
430
+ } catch (e: Exception) {
431
+ Log.e(TAG, "[START_CAMERA] Failed to start camera", e)
432
+ e.printStackTrace()
433
+ }
375
434
 
376
- cameraController?.startCamera(isUsingFrontCamera, true)
377
435
  if (isTorchEnabled) {
436
+ Log.d(TAG, "[START_CAMERA] Enabling torch...")
378
437
  cameraController?.setTorchEnabled(true)
379
438
  }
439
+
440
+ Log.d(TAG, "[START_CAMERA] Camera start completed")
380
441
  }
381
442
 
382
443
  fun stopCamera() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-rectangle-doc-scanner",
3
- "version": "3.154.0",
3
+ "version": "3.156.0",
4
4
  "description": "Native-backed document scanner for React Native with customizable overlays.",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",