react-native-rectangle-doc-scanner 3.152.0 → 3.154.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.
@@ -61,6 +61,9 @@ class DocumentScannerView(context: ThemedReactContext) : FrameLayout(context), L
61
61
  override fun getLifecycle(): Lifecycle = lifecycleRegistry
62
62
 
63
63
  init {
64
+ // Initialize lifecycle FIRST
65
+ lifecycleRegistry.currentState = Lifecycle.State.INITIALIZED
66
+
64
67
  // Create preview view
65
68
  previewView = PreviewView(context).apply {
66
69
  layoutParams = LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)
@@ -72,41 +75,31 @@ class DocumentScannerView(context: ThemedReactContext) : FrameLayout(context), L
72
75
  overlayView = OverlayView(context)
73
76
  addView(overlayView)
74
77
 
75
- // Setup camera
78
+ lifecycleRegistry.currentState = Lifecycle.State.CREATED
79
+ }
80
+
81
+ override fun onAttachedToWindow() {
82
+ super.onAttachedToWindow()
83
+ Log.d(TAG, "onAttachedToWindow called")
84
+
85
+ // Setup and start camera when view is attached
76
86
  post {
77
87
  setupCamera()
88
+ startCamera()
78
89
  }
79
-
80
- lifecycleRegistry.handleLifecycleEvent(Lifecycle.Event.ON_CREATE)
81
90
  }
82
91
 
83
92
  private fun setupCamera() {
84
93
  try {
85
- // Move to STARTED state first
86
- if (lifecycleRegistry.currentState != Lifecycle.State.DESTROYED) {
87
- lifecycleRegistry.handleLifecycleEvent(Lifecycle.Event.ON_START)
88
- }
89
-
90
94
  cameraController = CameraController(context, this, previewView)
91
95
  cameraController?.onFrameAnalyzed = { rectangle, imageWidth, imageHeight ->
92
96
  handleDetectionResult(rectangle, imageWidth, imageHeight)
93
97
  }
94
98
  lastDetectionTimestamp = 0L
95
99
 
96
- // Move to RESUMED state before starting camera
97
- if (lifecycleRegistry.currentState != Lifecycle.State.DESTROYED) {
98
- lifecycleRegistry.handleLifecycleEvent(Lifecycle.Event.ON_RESUME)
99
- }
100
-
101
- cameraController?.startCamera(isUsingFrontCamera, true)
102
- if (isTorchEnabled) {
103
- cameraController?.setTorchEnabled(true)
104
- }
105
-
106
100
  Log.d(TAG, "Camera setup completed")
107
101
  } catch (e: Exception) {
108
102
  Log.e(TAG, "Failed to setup camera", e)
109
- lifecycleRegistry.handleLifecycleEvent(Lifecycle.Event.ON_CREATE)
110
103
  }
111
104
  }
112
105
 
@@ -366,13 +359,18 @@ class DocumentScannerView(context: ThemedReactContext) : FrameLayout(context), L
366
359
  handleDetectionResult(rectangle, imageWidth, imageHeight)
367
360
  }
368
361
 
369
- // Ensure proper lifecycle state before starting camera
370
- if (lifecycleRegistry.currentState == Lifecycle.State.CREATED) {
371
- lifecycleRegistry.currentState = Lifecycle.State.STARTED
372
- }
373
- if (lifecycleRegistry.currentState != Lifecycle.State.DESTROYED) {
374
- lifecycleRegistry.handleLifecycleEvent(Lifecycle.Event.ON_START)
375
- lifecycleRegistry.handleLifecycleEvent(Lifecycle.Event.ON_RESUME)
362
+ // Transition lifecycle states properly
363
+ when (lifecycleRegistry.currentState) {
364
+ Lifecycle.State.CREATED -> {
365
+ lifecycleRegistry.currentState = Lifecycle.State.STARTED
366
+ lifecycleRegistry.currentState = Lifecycle.State.RESUMED
367
+ }
368
+ Lifecycle.State.STARTED -> {
369
+ lifecycleRegistry.currentState = Lifecycle.State.RESUMED
370
+ }
371
+ else -> {
372
+ // Already RESUMED or destroyed
373
+ }
376
374
  }
377
375
 
378
376
  cameraController?.startCamera(isUsingFrontCamera, true)
@@ -386,10 +384,20 @@ class DocumentScannerView(context: ThemedReactContext) : FrameLayout(context), L
386
384
  cameraController?.stopCamera()
387
385
  overlayView.setRectangle(null, overlayColor)
388
386
  stableCounter = 0
389
- if (lifecycleRegistry.currentState != Lifecycle.State.DESTROYED) {
390
- lifecycleRegistry.handleLifecycleEvent(Lifecycle.Event.ON_PAUSE)
391
- lifecycleRegistry.handleLifecycleEvent(Lifecycle.Event.ON_STOP)
392
- }
387
+
388
+ // Transition lifecycle back
389
+ when (lifecycleRegistry.currentState) {
390
+ Lifecycle.State.RESUMED -> {
391
+ lifecycleRegistry.currentState = Lifecycle.State.STARTED
392
+ lifecycleRegistry.currentState = Lifecycle.State.CREATED
393
+ }
394
+ Lifecycle.State.STARTED -> {
395
+ lifecycleRegistry.currentState = Lifecycle.State.CREATED
396
+ }
397
+ else -> {
398
+ // Already CREATED or destroyed
399
+ }
400
+ }
393
401
  } else {
394
402
  Log.d(TAG, "Cannot stop camera while capturing")
395
403
  }
@@ -422,7 +430,7 @@ class DocumentScannerView(context: ThemedReactContext) : FrameLayout(context), L
422
430
  private fun performCleanup() {
423
431
  Log.d(TAG, "Performing cleanup")
424
432
  cameraController?.stopCamera()
425
- lifecycleRegistry.handleLifecycleEvent(Lifecycle.Event.ON_DESTROY)
433
+ lifecycleRegistry.currentState = Lifecycle.State.DESTROYED
426
434
  cameraController?.shutdown()
427
435
  scope.cancel()
428
436
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-rectangle-doc-scanner",
3
- "version": "3.152.0",
3
+ "version": "3.154.0",
4
4
  "description": "Native-backed document scanner for React Native with customizable overlays.",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",