react-native-rectangle-doc-scanner 7.51.0 → 7.52.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.
@@ -559,14 +559,7 @@ class CameraController(
559
559
  val preview = previewSize ?: return
560
560
  if (viewWidth == 0f || viewHeight == 0f) return
561
561
 
562
- val rotation = previewView.display?.rotation ?: Surface.ROTATION_0
563
- val rotationDegrees = when (rotation) {
564
- Surface.ROTATION_0 -> 0
565
- Surface.ROTATION_90 -> 90
566
- Surface.ROTATION_180 -> 180
567
- Surface.ROTATION_270 -> 270
568
- else -> 0
569
- }
562
+ val rotationDegrees = computeRotationDegrees()
570
563
  Log.d(
571
564
  TAG,
572
565
  "[TRANSFORM] rotation=$rotationDegrees view=${viewWidth}x${viewHeight} preview=${preview.width}x${preview.height}"
@@ -577,28 +570,19 @@ class CameraController(
577
570
  val centerX = viewRect.centerX()
578
571
  val centerY = viewRect.centerY()
579
572
 
580
- val isSwapped = rotation == Surface.ROTATION_90 || rotation == Surface.ROTATION_270
581
- if (isSwapped) {
582
- val bufferRect = RectF(0f, 0f, preview.height.toFloat(), preview.width.toFloat())
583
- bufferRect.offset(centerX - bufferRect.centerX(), centerY - bufferRect.centerY())
584
- matrix.setRectToRect(viewRect, bufferRect, Matrix.ScaleToFit.FILL)
585
- val scale = max(
586
- viewHeight / preview.height.toFloat(),
587
- viewWidth / preview.width.toFloat()
588
- )
589
- matrix.postScale(scale, scale, centerX, centerY)
590
- matrix.postRotate(90f * (rotation - 2), centerX, centerY)
591
- } else {
592
- val bufferRect = RectF(0f, 0f, preview.width.toFloat(), preview.height.toFloat())
593
- matrix.setRectToRect(bufferRect, viewRect, Matrix.ScaleToFit.CENTER)
594
- val scale = max(
595
- viewWidth / preview.width.toFloat(),
596
- viewHeight / preview.height.toFloat()
597
- )
598
- matrix.postScale(scale, scale, centerX, centerY)
599
- if (rotation == Surface.ROTATION_180) {
600
- matrix.postRotate(180f, centerX, centerY)
601
- }
573
+ val isSwapped = rotationDegrees == 90 || rotationDegrees == 270
574
+ val bufferWidth = if (isSwapped) preview.height.toFloat() else preview.width.toFloat()
575
+ val bufferHeight = if (isSwapped) preview.width.toFloat() else preview.height.toFloat()
576
+ val scale = max(viewWidth / bufferWidth, viewHeight / bufferHeight)
577
+ val scaledWidth = bufferWidth * scale
578
+ val scaledHeight = bufferHeight * scale
579
+ val dx = (viewWidth - scaledWidth) / 2f
580
+ val dy = (viewHeight - scaledHeight) / 2f
581
+
582
+ matrix.setScale(scale, scale)
583
+ matrix.postTranslate(dx, dy)
584
+ if (rotationDegrees != 0) {
585
+ matrix.postRotate(rotationDegrees.toFloat(), centerX, centerY)
602
586
  }
603
587
 
604
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.51.0",
3
+ "version": "7.52.0",
4
4
  "description": "Native-backed document scanner for React Native with customizable overlays.",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",