react-native-rectangle-doc-scanner 7.45.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.
@@ -581,33 +581,36 @@ class CameraController(
581
581
 
582
582
  if (rotation == Surface.ROTATION_90 || rotation == Surface.ROTATION_270) {
583
583
  // When rotated 90/270, preview dimensions are swapped
584
- val swappedWidth = preview.height.toFloat()
585
- val swappedHeight = preview.width.toFloat()
584
+ val bufferWidth = preview.height.toFloat() // 1088
585
+ val bufferHeight = preview.width.toFloat() // 1920
586
586
 
587
- // Android: Use 90% of view height to add 10% padding (5% top + 5% bottom)
588
- val effectiveViewHeight = viewHeight * 0.90f
587
+ // Android: Use 90% of view height for 10% vertical padding
588
+ val effectiveHeight = viewHeight * 0.90f
589
589
 
590
- // Calculate scale to fit within the effective area while maintaining aspect ratio
591
- val scaleX = viewWidth / swappedWidth
592
- val scaleY = effectiveViewHeight / swappedHeight
593
- val scale = min(scaleX, scaleY)
590
+ // Create rectangles for the transformation
591
+ // bufferRect represents the camera preview texture (after rotation)
592
+ val bufferRect = RectF(0f, 0f, bufferHeight, bufferWidth)
593
+ val viewTargetRect = RectF(0f, 0f, viewWidth, effectiveHeight)
594
594
 
595
- // Calculate the final dimensions after scaling
596
- val scaledWidth = swappedWidth * scale
597
- val scaledHeight = swappedHeight * scale
595
+ // Calculate the center of viewTargetRect within the actual view
596
+ val targetCenterX = viewWidth / 2f
597
+ val targetCenterY = viewHeight / 2f
598
598
 
599
- // Create buffer rectangle at origin
600
- val bufferRectRotated = RectF(0f, 0f, swappedHeight, swappedWidth)
599
+ // Step 1: Map buffer rect to view target rect with CENTER mode (maintains aspect ratio)
600
+ matrix.setRectToRect(bufferRect, viewTargetRect, Matrix.ScaleToFit.CENTER)
601
601
 
602
- // Set up the matrix: scale and center the rotated preview
603
- matrix.setScale(scale, scale)
604
- matrix.postRotate(90f * (rotation - 2), scaledWidth / 2f, scaledHeight / 2f)
602
+ // Step 2: Translate to center of actual view
603
+ val scaledBufferWidth = bufferWidth * (effectiveHeight / bufferHeight)
604
+ val scaledBufferHeight = effectiveHeight
605
605
  matrix.postTranslate(
606
- centerX - scaledWidth / 2f,
607
- centerY - scaledHeight / 2f
606
+ targetCenterX - scaledBufferWidth / 2f,
607
+ targetCenterY - scaledBufferHeight / 2f
608
608
  )
609
609
 
610
- Log.d(TAG, "[TRANSFORM] Android: effectiveHeight=$effectiveViewHeight, scale=$scale, scaledSize=${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}")
611
614
  } else if (rotation == Surface.ROTATION_180) {
612
615
  matrix.postRotate(180f, centerX, centerY)
613
616
  } else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-rectangle-doc-scanner",
3
- "version": "7.45.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",