react-native-rectangle-doc-scanner 10.9.0 → 10.11.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.
@@ -123,9 +123,16 @@ class CameraController(
123
123
  request.resolution.height
124
124
  )
125
125
  val surface = Surface(surfaceTexture)
126
+
127
+ // Apply transform BEFORE providing surface
128
+ updateTextureViewTransform(
129
+ request.resolution.width,
130
+ request.resolution.height
131
+ )
132
+
126
133
  request.provideSurface(surface, ContextCompat.getMainExecutor(context)) { result ->
127
134
  Log.d(TAG, "[CAMERAX] Surface provided - result: ${result.resultCode}")
128
- surface.release()
135
+ // Don't release surface - let CameraX manage it
129
136
  }
130
137
  } else {
131
138
  Log.e(TAG, "[CAMERAX] SurfaceTexture is null! Waiting for TextureView to be ready...")
@@ -135,9 +142,16 @@ class CameraController(
135
142
  Log.d(TAG, "[CAMERAX] SurfaceTexture now available ($width x $height)")
136
143
  st.setDefaultBufferSize(request.resolution.width, request.resolution.height)
137
144
  val surface = Surface(st)
145
+
146
+ // Apply transform BEFORE providing surface
147
+ updateTextureViewTransform(
148
+ request.resolution.width,
149
+ request.resolution.height
150
+ )
151
+
138
152
  request.provideSurface(surface, ContextCompat.getMainExecutor(context)) { result ->
139
153
  Log.d(TAG, "[CAMERAX] Surface provided (delayed) - result: ${result.resultCode}")
140
- surface.release()
154
+ // Don't release surface - let CameraX manage it
141
155
  }
142
156
  }
143
157
 
@@ -425,4 +439,40 @@ class CameraController(
425
439
 
426
440
  return android.graphics.RectF(0f, 0f, width, height)
427
441
  }
442
+
443
+ private fun updateTextureViewTransform(bufferWidth: Int, bufferHeight: Int) {
444
+ val viewWidth = textureView.width
445
+ val viewHeight = textureView.height
446
+
447
+ if (viewWidth == 0 || viewHeight == 0) {
448
+ Log.w(TAG, "[TRANSFORM] View size is 0, skipping transform")
449
+ return
450
+ }
451
+
452
+ Log.d(TAG, "[TRANSFORM] View: ${viewWidth}x${viewHeight}, Buffer: ${bufferWidth}x${bufferHeight}")
453
+
454
+ val matrix = android.graphics.Matrix()
455
+ val centerX = viewWidth / 2f
456
+ val centerY = viewHeight / 2f
457
+
458
+ // Camera sensor is landscape (1440x1088), but we want portrait display
459
+ // Rotate 90 degrees clockwise to make it portrait
460
+ matrix.postRotate(90f, centerX, centerY)
461
+
462
+ // After rotation, the buffer dimensions are swapped
463
+ val rotatedBufferWidth = bufferHeight // 1088
464
+ val rotatedBufferHeight = bufferWidth // 1440
465
+
466
+ // Scale to fill the view while maintaining aspect ratio
467
+ val scaleX = viewWidth.toFloat() / rotatedBufferWidth.toFloat()
468
+ val scaleY = viewHeight.toFloat() / rotatedBufferHeight.toFloat()
469
+ val scale = scaleX.coerceAtLeast(scaleY) // Use max to fill
470
+
471
+ Log.d(TAG, "[TRANSFORM] ScaleX: $scaleX, ScaleY: $scaleY, Using: $scale")
472
+
473
+ matrix.postScale(scale, scale, centerX, centerY)
474
+
475
+ textureView.setTransform(matrix)
476
+ Log.d(TAG, "[TRANSFORM] Transform applied successfully")
477
+ }
428
478
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-rectangle-doc-scanner",
3
- "version": "10.9.0",
3
+ "version": "10.11.0",
4
4
  "description": "Native-backed document scanner for React Native with customizable overlays.",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",