react-native-rectangle-doc-scanner 7.24.0 → 7.25.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.
@@ -564,27 +564,25 @@ class CameraController(
564
564
  )
565
565
 
566
566
  val matrix = Matrix()
567
- val isSwapped = rotation == Surface.ROTATION_90 || rotation == Surface.ROTATION_270
568
- val bufferWidth = if (isSwapped) preview.height.toFloat() else preview.width.toFloat()
569
- val bufferHeight = if (isSwapped) preview.width.toFloat() else preview.height.toFloat()
570
567
  val viewRect = RectF(0f, 0f, viewWidth, viewHeight)
571
- val bufferRect = RectF(0f, 0f, bufferWidth, bufferHeight)
568
+ val bufferRect = RectF(0f, 0f, preview.height.toFloat(), preview.width.toFloat())
572
569
  val centerX = viewRect.centerX()
573
570
  val centerY = viewRect.centerY()
574
571
 
575
- // Preserve aspect ratio, then scale to fill (center-crop) without distortion.
576
- matrix.setRectToRect(bufferRect, viewRect, Matrix.ScaleToFit.CENTER)
577
- val scale = max(viewWidth / bufferWidth, viewHeight / bufferHeight)
578
- matrix.postScale(scale, scale, centerX, centerY)
579
-
580
- if (rotation != Surface.ROTATION_0) {
581
- val rotateDegrees = when (rotation) {
582
- Surface.ROTATION_90 -> -90f
583
- Surface.ROTATION_180 -> 180f
584
- Surface.ROTATION_270 -> 90f
585
- else -> 0f
586
- }
587
- matrix.postRotate(rotateDegrees, centerX, centerY)
572
+ if (rotation == Surface.ROTATION_90 || rotation == Surface.ROTATION_270) {
573
+ bufferRect.offset(centerX - bufferRect.centerX(), centerY - bufferRect.centerY())
574
+ matrix.setRectToRect(viewRect, bufferRect, Matrix.ScaleToFit.FILL)
575
+ val scale = max(viewHeight / preview.height.toFloat(), viewWidth / preview.width.toFloat())
576
+ matrix.postScale(scale, scale, centerX, centerY)
577
+ matrix.postRotate(90f * (rotation - 2), centerX, centerY)
578
+ } else if (rotation == Surface.ROTATION_180) {
579
+ matrix.postRotate(180f, centerX, centerY)
580
+ } else {
581
+ val scale = max(viewWidth / preview.width.toFloat(), viewHeight / preview.height.toFloat())
582
+ val scaledWidth = preview.width.toFloat() * scale
583
+ val scaledHeight = preview.height.toFloat() * scale
584
+ matrix.setScale(scale, scale)
585
+ matrix.postTranslate((viewWidth - scaledWidth) / 2f, (viewHeight - scaledHeight) / 2f)
588
586
  }
589
587
 
590
588
  previewView.setTransform(matrix)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-rectangle-doc-scanner",
3
- "version": "7.24.0",
3
+ "version": "7.25.0",
4
4
  "description": "Native-backed document scanner for React Native with customizable overlays.",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",