react-native-rectangle-doc-scanner 10.39.0 → 10.40.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.
@@ -118,9 +118,8 @@ class CameraController(
118
118
  Log.d(TAG, "[CAMERAX] TextureView visibility: ${textureView.visibility}")
119
119
  Log.d(TAG, "[CAMERAX] TextureView isAvailable: ${textureView.isAvailable}")
120
120
 
121
- // Force portrait orientation (app is portrait-only)
122
- val targetRotation = android.view.Surface.ROTATION_0
123
- Log.d(TAG, "[CAMERAX] Setting target rotation to ROTATION_0 (portrait-only app)")
121
+ val targetRotation = textureView.display?.rotation ?: android.view.Surface.ROTATION_0
122
+ Log.d(TAG, "[CAMERAX] Setting target rotation to $targetRotation")
124
123
 
125
124
  preview = Preview.Builder()
126
125
  .setTargetAspectRatio(AspectRatio.RATIO_4_3)
@@ -496,8 +495,6 @@ class CameraController(
496
495
  return
497
496
  }
498
497
 
499
- // Get sensor orientation to determine correct rotation
500
- val sensorOrientation = getCameraSensorOrientation()
501
498
  val displayRotationDegrees = when (textureView.display?.rotation ?: Surface.ROTATION_0) {
502
499
  Surface.ROTATION_0 -> 0
503
500
  Surface.ROTATION_90 -> 90
@@ -509,34 +506,16 @@ class CameraController(
509
506
  Log.d(
510
507
  TAG,
511
508
  "[TRANSFORM] View: ${viewWidth}x${viewHeight}, Buffer: ${bufferWidth}x${bufferHeight}, " +
512
- "Sensor: ${sensorOrientation}°, Display: ${displayRotationDegrees}°"
509
+ "Display: ${displayRotationDegrees}°"
513
510
  )
514
511
 
515
512
  val matrix = android.graphics.Matrix()
516
513
  val centerX = viewWidth / 2f
517
514
  val centerY = viewHeight / 2f
518
515
 
519
- // Calculate rotation from buffer to display coordinates.
520
- // CameraX provides buffers in sensor orientation; rotate to match display.
521
- val rotationDegrees = ((sensorOrientation - displayRotationDegrees + 360) % 360).toFloat()
522
-
523
- Log.d(TAG, "[TRANSFORM] Applying rotation: ${rotationDegrees}°")
524
-
525
- if (rotationDegrees != 0f) {
526
- matrix.postRotate(rotationDegrees, centerX, centerY)
527
- }
528
-
529
- // After rotation, determine effective buffer size
530
- val rotatedBufferWidth = if (rotationDegrees == 90f || rotationDegrees == 270f) {
531
- bufferHeight
532
- } else {
533
- bufferWidth
534
- }
535
- val rotatedBufferHeight = if (rotationDegrees == 90f || rotationDegrees == 270f) {
536
- bufferWidth
537
- } else {
538
- bufferHeight
539
- }
516
+ // Preview buffers are already rotated to match targetRotation.
517
+ val rotatedBufferWidth = bufferWidth
518
+ val rotatedBufferHeight = bufferHeight
540
519
 
541
520
  // Scale to fill the view while maintaining aspect ratio (center-crop).
542
521
  val scaleX = viewWidth.toFloat() / rotatedBufferWidth.toFloat()
@@ -121,24 +121,14 @@ const mirrorRectangleHorizontally = (rectangle, imageWidth) => ({
121
121
  const mapRectangleToView = (rectangle, imageWidth, imageHeight, viewWidth, viewHeight, density) => {
122
122
  const viewWidthPx = viewWidth * density;
123
123
  const viewHeightPx = viewHeight * density;
124
- const scale = react_native_1.Platform.OS === 'ios'
125
- ? Math.max(viewWidthPx / imageWidth, viewHeightPx / imageHeight)
126
- : Math.min(viewWidthPx / imageWidth, viewHeightPx / imageHeight);
124
+ const scale = Math.max(viewWidthPx / imageWidth, viewHeightPx / imageHeight);
127
125
  const scaledImageWidth = imageWidth * scale;
128
126
  const scaledImageHeight = imageHeight * scale;
129
- const offsetX = react_native_1.Platform.OS === 'ios'
130
- ? (scaledImageWidth - viewWidthPx) / 2
131
- : (viewWidthPx - scaledImageWidth) / 2;
132
- const offsetY = react_native_1.Platform.OS === 'ios'
133
- ? (scaledImageHeight - viewHeightPx) / 2
134
- : (viewHeightPx - scaledImageHeight) / 2;
127
+ const offsetX = (scaledImageWidth - viewWidthPx) / 2;
128
+ const offsetY = (scaledImageHeight - viewHeightPx) / 2;
135
129
  const mapPoint = (point) => ({
136
- x: react_native_1.Platform.OS === 'ios'
137
- ? (point.x * scale - offsetX) / density
138
- : (point.x * scale + offsetX) / density,
139
- y: react_native_1.Platform.OS === 'ios'
140
- ? (point.y * scale - offsetY) / density
141
- : (point.y * scale + offsetY) / density,
130
+ x: (point.x * scale - offsetX) / density,
131
+ y: (point.y * scale - offsetY) / density,
142
132
  });
143
133
  return {
144
134
  topLeft: mapPoint(rectangle.topLeft),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-rectangle-doc-scanner",
3
- "version": "10.39.0",
3
+ "version": "10.40.0",
4
4
  "description": "Native-backed document scanner for React Native with customizable overlays.",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",
@@ -188,30 +188,15 @@ const mapRectangleToView = (
188
188
  ): Rectangle => {
189
189
  const viewWidthPx = viewWidth * density;
190
190
  const viewHeightPx = viewHeight * density;
191
- const scale =
192
- Platform.OS === 'ios'
193
- ? Math.max(viewWidthPx / imageWidth, viewHeightPx / imageHeight)
194
- : Math.min(viewWidthPx / imageWidth, viewHeightPx / imageHeight);
191
+ const scale = Math.max(viewWidthPx / imageWidth, viewHeightPx / imageHeight);
195
192
  const scaledImageWidth = imageWidth * scale;
196
193
  const scaledImageHeight = imageHeight * scale;
197
- const offsetX =
198
- Platform.OS === 'ios'
199
- ? (scaledImageWidth - viewWidthPx) / 2
200
- : (viewWidthPx - scaledImageWidth) / 2;
201
- const offsetY =
202
- Platform.OS === 'ios'
203
- ? (scaledImageHeight - viewHeightPx) / 2
204
- : (viewHeightPx - scaledImageHeight) / 2;
194
+ const offsetX = (scaledImageWidth - viewWidthPx) / 2;
195
+ const offsetY = (scaledImageHeight - viewHeightPx) / 2;
205
196
 
206
197
  const mapPoint = (point: Point): Point => ({
207
- x:
208
- Platform.OS === 'ios'
209
- ? (point.x * scale - offsetX) / density
210
- : (point.x * scale + offsetX) / density,
211
- y:
212
- Platform.OS === 'ios'
213
- ? (point.y * scale - offsetY) / density
214
- : (point.y * scale + offsetY) / density,
198
+ x: (point.x * scale - offsetX) / density,
199
+ y: (point.y * scale - offsetY) / density,
215
200
  });
216
201
 
217
202
  return {