react-native-rectangle-doc-scanner 7.46.0 → 7.47.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.
@@ -587,31 +587,30 @@ class CameraController(
587
587
  // Android: Use 90% of view height for 10% vertical padding
588
588
  val effectiveHeight = viewHeight * 0.90f
589
589
 
590
- // Calculate scale to fit the preview proportionally
591
- // Use min to ensure entire preview fits (no cropping, no stretching)
592
- val scaleX = viewWidth / bufferWidth
593
- val scaleY = effectiveHeight / bufferHeight
594
- val scale = min(scaleX, scaleY) // This maintains aspect ratio
595
-
596
- // Create swap buffer rect (before rotation: height x width)
590
+ // Create rectangles for the transformation
591
+ // bufferRect represents the camera preview texture (after rotation)
597
592
  val bufferRect = RectF(0f, 0f, bufferHeight, bufferWidth)
593
+ val viewTargetRect = RectF(0f, 0f, viewWidth, effectiveHeight)
598
594
 
599
- // Apply the transformation
600
- // 1. Scale uniformly to fit in view
601
- matrix.postScale(scale, scale)
595
+ // Calculate the center of viewTargetRect within the actual view
596
+ val targetCenterX = viewWidth / 2f
597
+ val targetCenterY = viewHeight / 2f
602
598
 
603
- // 2. Rotate 90 degrees
604
- val scaledWidth = bufferWidth * scale
605
- val scaledHeight = bufferHeight * scale
606
- matrix.postRotate(90f * (rotation - 2), scaledHeight / 2f, scaledWidth / 2f)
599
+ // Step 1: Map buffer rect to view target rect with CENTER mode (maintains aspect ratio)
600
+ matrix.setRectToRect(bufferRect, viewTargetRect, Matrix.ScaleToFit.CENTER)
607
601
 
608
- // 3. Center in view
602
+ // Step 2: Translate to center of actual view
603
+ val scaledBufferWidth = bufferWidth * (effectiveHeight / bufferHeight)
604
+ val scaledBufferHeight = effectiveHeight
609
605
  matrix.postTranslate(
610
- centerX - scaledHeight / 2f,
611
- centerY - scaledWidth / 2f
606
+ targetCenterX - scaledBufferWidth / 2f,
607
+ targetCenterY - scaledBufferHeight / 2f
612
608
  )
613
609
 
614
- Log.d(TAG, "[TRANSFORM] Android: buffer=${bufferWidth}x${bufferHeight}, scale=$scale, final=${scaledWidth}x${scaledHeight}")
610
+ // Step 3: Rotate around the center
611
+ matrix.postRotate(90f * (rotation - 2), targetCenterX, targetCenterY)
612
+
613
+ Log.d(TAG, "[TRANSFORM] Android: buffer=${bufferWidth}x${bufferHeight}, effectiveH=$effectiveHeight, target=${scaledBufferWidth}x${scaledBufferHeight}")
615
614
  } else if (rotation == Surface.ROTATION_180) {
616
615
  matrix.postRotate(180f, centerX, centerY)
617
616
  } else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-rectangle-doc-scanner",
3
- "version": "7.46.0",
3
+ "version": "7.47.0",
4
4
  "description": "Native-backed document scanner for React Native with customizable overlays.",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",