react-native-rectangle-doc-scanner 3.151.0 → 3.153.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.
@@ -62,7 +62,7 @@ class CameraView(context: Context) : FrameLayout(context), LifecycleOwner {
62
62
  addView(overlayView)
63
63
 
64
64
  Log.d(TAG, "CameraView initialized")
65
- lifecycleRegistry.currentState = Lifecycle.State.CREATED
65
+ lifecycleRegistry.handleLifecycleEvent(Lifecycle.Event.ON_CREATE)
66
66
  }
67
67
 
68
68
  /**
@@ -91,7 +91,8 @@ class CameraView(context: Context) : FrameLayout(context), LifecycleOwner {
91
91
  fun stopCamera() {
92
92
  cameraProvider?.unbindAll()
93
93
  if (lifecycleRegistry.currentState != Lifecycle.State.DESTROYED) {
94
- lifecycleRegistry.currentState = Lifecycle.State.CREATED
94
+ lifecycleRegistry.handleLifecycleEvent(Lifecycle.Event.ON_PAUSE)
95
+ lifecycleRegistry.handleLifecycleEvent(Lifecycle.Event.ON_STOP)
95
96
  }
96
97
  }
97
98
 
@@ -115,6 +116,11 @@ class CameraView(context: Context) : FrameLayout(context), LifecycleOwner {
115
116
  // Unbind all before rebinding
116
117
  provider.unbindAll()
117
118
 
119
+ if (lifecycleRegistry.currentState != Lifecycle.State.DESTROYED) {
120
+ lifecycleRegistry.handleLifecycleEvent(Lifecycle.Event.ON_START)
121
+ lifecycleRegistry.handleLifecycleEvent(Lifecycle.Event.ON_RESUME)
122
+ }
123
+
118
124
  // Preview use case
119
125
  preview = Preview.Builder()
120
126
  .build()
@@ -222,7 +228,7 @@ class CameraView(context: Context) : FrameLayout(context), LifecycleOwner {
222
228
  override fun onDetachedFromWindow() {
223
229
  super.onDetachedFromWindow()
224
230
  stopCamera()
225
- lifecycleRegistry.currentState = Lifecycle.State.DESTROYED
231
+ lifecycleRegistry.handleLifecycleEvent(Lifecycle.Event.ON_DESTROY)
226
232
  if (!cameraExecutor.isShutdown) {
227
233
  cameraExecutor.shutdown()
228
234
  }
@@ -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.currentState = Lifecycle.State.CREATED
81
90
  }
82
91
 
83
92
  private fun setupCamera() {
84
93
  try {
85
- // Move to STARTED state first
86
- if (lifecycleRegistry.currentState == Lifecycle.State.CREATED) {
87
- lifecycleRegistry.currentState = Lifecycle.State.STARTED
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.currentState = Lifecycle.State.RESUMED
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.currentState = Lifecycle.State.CREATED
110
103
  }
111
104
  }
112
105
 
@@ -366,12 +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.currentState = Lifecycle.State.RESUMED
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
+ }
375
374
  }
376
375
 
377
376
  cameraController?.startCamera(isUsingFrontCamera, true)
@@ -385,8 +384,19 @@ class DocumentScannerView(context: ThemedReactContext) : FrameLayout(context), L
385
384
  cameraController?.stopCamera()
386
385
  overlayView.setRectangle(null, overlayColor)
387
386
  stableCounter = 0
388
- if (lifecycleRegistry.currentState != Lifecycle.State.DESTROYED) {
389
- lifecycleRegistry.currentState = Lifecycle.State.CREATED
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
+ }
390
400
  }
391
401
  } else {
392
402
  Log.d(TAG, "Cannot stop camera while capturing")
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-rectangle-doc-scanner",
3
- "version": "3.151.0",
3
+ "version": "3.153.0",
4
4
  "description": "Native-backed document scanner for React Native with customizable overlays.",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",