react-native-rectangle-doc-scanner 3.174.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.
@@ -145,6 +145,7 @@ class CameraController(
145
145
  Log.d(TAG, "[BIND] PreviewView.surfaceProvider: ${previewView.surfaceProvider}")
146
146
  Log.d(TAG, "[BIND] PreviewView attached to window: ${previewView.isAttachedToWindow}")
147
147
  Log.d(TAG, "[BIND] PreviewView size: ${previewView.width}x${previewView.height}")
148
+ Log.d(TAG, "[BIND] PreviewView implementationMode: ${previewView.implementationMode}")
148
149
  // Unbind all use cases before rebinding
149
150
  Log.d(TAG, "[BIND] Unbinding all existing use cases...")
150
151
  cameraProvider.unbindAll()
@@ -167,10 +168,15 @@ class CameraController(
167
168
  Log.d(TAG, "[BIND] Setting surface provider to previewView...")
168
169
  Log.d(TAG, "[BIND] PreviewView: $previewView")
169
170
  Log.d(TAG, "[BIND] PreviewView.surfaceProvider: ${previewView.surfaceProvider}")
170
- // Devices with the SurfaceOrderQuirk expect the preview surface to be set last.
171
- // Apply the SurfaceProvider after binding so the preview stays on top.
172
- preview.setSurfaceProvider(previewView.surfaceProvider)
173
- Log.d(TAG, "[BIND] Surface provider set successfully")
171
+ // TextureView(Compatibility) 모드에서는 SurfaceProvider를 먼저 지정해도 순서 문제가 없다.
172
+ // PERFORMANCE 모드(SurfaceView)에서는 SurfaceOrderQuirk 대응을 위해 바인딩 이후에 지정한다.
173
+ if (previewView.implementationMode == PreviewView.ImplementationMode.COMPATIBLE) {
174
+ preview.setSurfaceProvider(previewView.surfaceProvider)
175
+ Log.d(TAG, "[BIND] Surface provider set immediately (COMPATIBLE mode)")
176
+ } else {
177
+ preview.setSurfaceProvider(previewView.surfaceProvider)
178
+ Log.d(TAG, "[BIND] Surface provider set after binding (PERFORMANCE mode)")
179
+ }
174
180
 
175
181
  // Restore torch state if it was enabled
176
182
  if (torchEnabled) {
@@ -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.174.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",