react-native-rectangle-doc-scanner 10.8.0 → 10.10.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.
@@ -101,8 +101,12 @@ class CameraController(
101
101
  Log.d(TAG, "[CAMERAX] TextureView visibility: ${textureView.visibility}")
102
102
  Log.d(TAG, "[CAMERAX] TextureView isAvailable: ${textureView.isAvailable}")
103
103
 
104
+ // Force portrait orientation (app is portrait-only)
105
+ val targetRotation = android.view.Surface.ROTATION_0
106
+ Log.d(TAG, "[CAMERAX] Setting target rotation to ROTATION_0 (portrait-only app)")
107
+
104
108
  preview = Preview.Builder()
105
- .setTargetResolution(android.util.Size(1920, 1080)) // 16:9 resolution
109
+ .setTargetRotation(targetRotation) // Force portrait
106
110
  .build()
107
111
  .also { previewUseCase ->
108
112
  Log.d(TAG, "[CAMERAX] Setting SurfaceProvider for TextureView...")
@@ -121,6 +125,15 @@ class CameraController(
121
125
  val surface = Surface(surfaceTexture)
122
126
  request.provideSurface(surface, ContextCompat.getMainExecutor(context)) { result ->
123
127
  Log.d(TAG, "[CAMERAX] Surface provided - result: ${result.resultCode}")
128
+
129
+ // Apply transform to correct orientation
130
+ textureView.post {
131
+ updateTextureViewTransform(
132
+ request.resolution.width,
133
+ request.resolution.height
134
+ )
135
+ }
136
+
124
137
  surface.release()
125
138
  }
126
139
  } else {
@@ -133,6 +146,15 @@ class CameraController(
133
146
  val surface = Surface(st)
134
147
  request.provideSurface(surface, ContextCompat.getMainExecutor(context)) { result ->
135
148
  Log.d(TAG, "[CAMERAX] Surface provided (delayed) - result: ${result.resultCode}")
149
+
150
+ // Apply transform to correct orientation
151
+ textureView.post {
152
+ updateTextureViewTransform(
153
+ request.resolution.width,
154
+ request.resolution.height
155
+ )
156
+ }
157
+
136
158
  surface.release()
137
159
  }
138
160
  }
@@ -151,6 +173,7 @@ class CameraController(
151
173
  imageAnalyzer = ImageAnalysis.Builder()
152
174
  .setBackpressureStrategy(ImageAnalysis.STRATEGY_KEEP_ONLY_LATEST)
153
175
  .setTargetResolution(android.util.Size(1280, 960)) // Limit resolution for analysis
176
+ .setTargetRotation(targetRotation) // Match preview rotation
154
177
  .build()
155
178
  .also {
156
179
  it.setAnalyzer(cameraExecutor) { imageProxy ->
@@ -165,6 +188,7 @@ class CameraController(
165
188
  // ImageCapture UseCase
166
189
  imageCapture = ImageCapture.Builder()
167
190
  .setCaptureMode(ImageCapture.CAPTURE_MODE_MAXIMIZE_QUALITY)
191
+ .setTargetRotation(targetRotation) // Match preview rotation
168
192
  .build()
169
193
 
170
194
  try {
@@ -419,4 +443,40 @@ class CameraController(
419
443
 
420
444
  return android.graphics.RectF(0f, 0f, width, height)
421
445
  }
446
+
447
+ private fun updateTextureViewTransform(bufferWidth: Int, bufferHeight: Int) {
448
+ val viewWidth = textureView.width
449
+ val viewHeight = textureView.height
450
+
451
+ if (viewWidth == 0 || viewHeight == 0) {
452
+ Log.w(TAG, "[TRANSFORM] View size is 0, skipping transform")
453
+ return
454
+ }
455
+
456
+ Log.d(TAG, "[TRANSFORM] View: ${viewWidth}x${viewHeight}, Buffer: ${bufferWidth}x${bufferHeight}")
457
+
458
+ val matrix = android.graphics.Matrix()
459
+ val centerX = viewWidth / 2f
460
+ val centerY = viewHeight / 2f
461
+
462
+ // Camera sensor is landscape (1440x1088), but we want portrait display
463
+ // Rotate 90 degrees clockwise to make it portrait
464
+ matrix.postRotate(90f, centerX, centerY)
465
+
466
+ // After rotation, the buffer dimensions are swapped
467
+ val rotatedBufferWidth = bufferHeight // 1088
468
+ val rotatedBufferHeight = bufferWidth // 1440
469
+
470
+ // Scale to fill the view while maintaining aspect ratio
471
+ val scaleX = viewWidth.toFloat() / rotatedBufferWidth.toFloat()
472
+ val scaleY = viewHeight.toFloat() / rotatedBufferHeight.toFloat()
473
+ val scale = scaleX.coerceAtLeast(scaleY) // Use max to fill
474
+
475
+ Log.d(TAG, "[TRANSFORM] ScaleX: $scaleX, ScaleY: $scaleY, Using: $scale")
476
+
477
+ matrix.postScale(scale, scale, centerX, centerY)
478
+
479
+ textureView.setTransform(matrix)
480
+ Log.d(TAG, "[TRANSFORM] Transform applied successfully")
481
+ }
422
482
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-rectangle-doc-scanner",
3
- "version": "10.8.0",
3
+ "version": "10.10.0",
4
4
  "description": "Native-backed document scanner for React Native with customizable overlays.",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",