react-native-rectangle-doc-scanner 7.37.0 → 7.38.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.
@@ -565,29 +565,23 @@ class CameraController(
565
565
  "[TRANSFORM] rotation=${displayRotationDegrees()} view=${viewWidth}x${viewHeight} preview=${preview.width}x${preview.height}"
566
566
  )
567
567
 
568
+ val rotationDegrees = displayRotationDegrees()
569
+ val bufferWidth = preview.width.toFloat()
570
+ val bufferHeight = preview.height.toFloat()
571
+ val isSwapped = rotationDegrees == 90 || rotationDegrees == 270
572
+ val rotatedWidth = if (isSwapped) bufferHeight else bufferWidth
573
+ val rotatedHeight = if (isSwapped) bufferWidth else bufferHeight
574
+ val scale = max(viewWidth / rotatedWidth, viewHeight / rotatedHeight)
575
+ val rotateDegrees = -rotationDegrees.toFloat()
576
+
577
+ // Rotate around buffer center, then scale uniformly and center in the view (aspect-fill).
568
578
  val matrix = Matrix()
569
- val viewRect = RectF(0f, 0f, viewWidth, viewHeight)
570
- val bufferRect = if (rotation == Surface.ROTATION_90 || rotation == Surface.ROTATION_270) {
571
- RectF(0f, 0f, preview.height.toFloat(), preview.width.toFloat())
572
- } else {
573
- RectF(0f, 0f, preview.width.toFloat(), preview.height.toFloat())
574
- }
575
- val centerX = viewRect.centerX()
576
- val centerY = viewRect.centerY()
577
-
578
- // Center-crop without distortion for all rotations.
579
- matrix.setRectToRect(bufferRect, viewRect, Matrix.ScaleToFit.CENTER)
580
- val scale = max(viewWidth / bufferRect.width(), viewHeight / bufferRect.height())
581
- matrix.postScale(scale, scale, centerX, centerY)
582
- val rotateDegrees = when (rotation) {
583
- Surface.ROTATION_90 -> -90f
584
- Surface.ROTATION_180 -> 180f
585
- Surface.ROTATION_270 -> 90f
586
- else -> 0f
587
- }
579
+ matrix.postTranslate(-bufferWidth / 2f, -bufferHeight / 2f)
588
580
  if (rotateDegrees != 0f) {
589
- matrix.postRotate(rotateDegrees, centerX, centerY)
581
+ matrix.postRotate(rotateDegrees)
590
582
  }
583
+ matrix.postScale(scale, scale)
584
+ matrix.postTranslate(viewWidth / 2f, viewHeight / 2f)
591
585
 
592
586
  previewView.setTransform(matrix)
593
587
  Log.d(TAG, "[TRANSFORM] Matrix applied successfully")
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-rectangle-doc-scanner",
3
- "version": "7.37.0",
3
+ "version": "7.38.0",
4
4
  "description": "Native-backed document scanner for React Native with customizable overlays.",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",