react-native-rectangle-doc-scanner 3.175.0 → 3.176.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.
@@ -119,21 +119,42 @@ class DocumentScannerView(context: ThemedReactContext) : FrameLayout(context), L
119
119
  lifecycleRegistry.handleLifecycleEvent(Lifecycle.Event.ON_START)
120
120
  lifecycleRegistry.handleLifecycleEvent(Lifecycle.Event.ON_RESUME)
121
121
 
122
- // Wait for view to be laid out before starting camera
123
- viewTreeObserver.addOnGlobalLayoutListener(object : android.view.ViewTreeObserver.OnGlobalLayoutListener {
124
- override fun onGlobalLayout() {
125
- viewTreeObserver.removeOnGlobalLayoutListener(this)
126
-
127
- if (width > 0 && height > 0 && previewView.width > 0 && previewView.height > 0) {
128
- Log.d(TAG, "[LAYOUT] View laid out: width=$width, height=$height")
129
- Log.d(TAG, "[LAYOUT] PreviewView: width=${previewView.width}, height=${previewView.height}")
122
+ // Initialize camera immediately or on next layout
123
+ initializeCameraWhenReady()
124
+ }
125
+
126
+ private fun initializeCameraWhenReady() {
127
+ // If view is already laid out, start camera immediately
128
+ if (width > 0 && height > 0) {
129
+ Log.d(TAG, "[INIT] View already laid out, starting camera immediately")
130
+ Log.d(TAG, "[INIT] View: width=$width, height=$height")
131
+ Log.d(TAG, "[INIT] PreviewView: width=${previewView.width}, height=${previewView.height}")
132
+ setupCamera()
133
+ startCamera()
134
+ } else {
135
+ // Otherwise, wait for layout
136
+ Log.d(TAG, "[INIT] View not laid out yet, waiting for layout")
137
+ post {
138
+ if (width > 0 && height > 0) {
139
+ Log.d(TAG, "[INIT] View laid out after post: width=$width, height=$height")
130
140
  setupCamera()
131
141
  startCamera()
132
142
  } else {
133
- Log.e(TAG, "[LAYOUT] View or PreviewView has invalid dimensions")
143
+ // Fallback: use ViewTreeObserver if still not ready
144
+ Log.d(TAG, "[INIT] Still not laid out, using ViewTreeObserver")
145
+ viewTreeObserver.addOnGlobalLayoutListener(object : android.view.ViewTreeObserver.OnGlobalLayoutListener {
146
+ override fun onGlobalLayout() {
147
+ if (width > 0 && height > 0) {
148
+ viewTreeObserver.removeOnGlobalLayoutListener(this)
149
+ Log.d(TAG, "[INIT] View laid out via observer: width=$width, height=$height")
150
+ setupCamera()
151
+ startCamera()
152
+ }
153
+ }
154
+ })
134
155
  }
135
156
  }
136
- })
157
+ }
137
158
  }
138
159
 
139
160
  private fun setupCamera() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-rectangle-doc-scanner",
3
- "version": "3.175.0",
3
+ "version": "3.176.0",
4
4
  "description": "Native-backed document scanner for React Native with customizable overlays.",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",