react-native-rectangle-doc-scanner 7.10.0 → 7.11.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.
@@ -523,15 +523,12 @@ class CameraController(
523
523
 
524
524
  private fun computeRotationDegrees(): Int {
525
525
  val displayRotation = displayRotationDegrees()
526
-
527
- // For back camera with sensor orientation 0 and display rotation 90 (portrait),
528
- // we need 270 degree rotation to display correctly
526
+ val baseRotation = (sensorOrientation + displayRotation) % 360
529
527
  val rotation = if (useFrontCamera) {
530
- (sensorOrientation + displayRotation) % 360
528
+ (360 - baseRotation) % 360
531
529
  } else {
532
- (sensorOrientation - displayRotation + 360) % 360
530
+ baseRotation
533
531
  }
534
-
535
532
  Log.d(TAG, "[ROTATION] sensor=$sensorOrientation display=$displayRotation front=$useFrontCamera -> rotation=$rotation")
536
533
  return rotation
537
534
  }
@@ -552,47 +549,28 @@ class CameraController(
552
549
  val viewHeight = previewView.height.toFloat()
553
550
  val preview = previewSize ?: return
554
551
  if (viewWidth == 0f || viewHeight == 0f) return
555
-
556
- val rotation = computeRotationDegrees()
557
- Log.d(TAG, "[TRANSFORM] rotation=$rotation view=${viewWidth}x${viewHeight} preview=${preview.width}x${preview.height}")
552
+ val rotation = previewView.display?.rotation ?: Surface.ROTATION_0
553
+ val rotationDegrees = displayRotationDegrees()
554
+ Log.d(TAG, "[TRANSFORM] rotation=$rotationDegrees view=${viewWidth}x${viewHeight} preview=${preview.width}x${preview.height}")
558
555
 
559
556
  val matrix = Matrix()
560
- val centerX = viewWidth / 2f
561
- val centerY = viewHeight / 2f
562
-
563
- // Match iOS behavior: use the full preview extent and scale to fill
564
- if (rotation == 270 || rotation == 90) {
565
- // After rotation, dimensions are swapped
566
- val rotatedWidth = preview.height.toFloat()
567
- val rotatedHeight = preview.width.toFloat()
568
-
569
- Log.d(TAG, "[TRANSFORM] After rotation: ${rotatedWidth}x${rotatedHeight}")
570
-
571
- // Calculate scale to completely fill the view (aspect fill - crop mode like iOS)
572
- // This will crop the image but fill the entire screen
573
- val scaleX = viewWidth / rotatedWidth
574
- val scaleY = viewHeight / rotatedHeight
575
- val scale = maxOf(scaleX, scaleY)
576
-
577
- Log.d(TAG, "[TRANSFORM] scaleX=$scaleX scaleY=$scaleY finalScale=$scale")
578
-
579
- // Apply rotation around center first
580
- matrix.postRotate(rotation.toFloat(), centerX, centerY)
581
-
582
- // Then scale to fill (will crop excess)
583
- matrix.postScale(scale, scale, centerX, centerY)
584
- } else {
585
- // For 0 or 180 degree rotation
586
- val scaleX = viewWidth / preview.width.toFloat()
587
- val scaleY = viewHeight / preview.height.toFloat()
588
- val scale = maxOf(scaleX, scaleY)
589
-
590
- Log.d(TAG, "[TRANSFORM] scaleX=$scaleX scaleY=$scaleY finalScale=$scale")
591
-
592
- if (rotation != 0) {
593
- matrix.postRotate(rotation.toFloat(), centerX, centerY)
594
- }
557
+ val viewRect = RectF(0f, 0f, viewWidth, viewHeight)
558
+ val bufferRect = RectF(0f, 0f, preview.height.toFloat(), preview.width.toFloat())
559
+ val centerX = viewRect.centerX()
560
+ val centerY = viewRect.centerY()
561
+
562
+ if (rotation == Surface.ROTATION_90 || rotation == Surface.ROTATION_270) {
563
+ bufferRect.offset(centerX - bufferRect.centerX(), centerY - bufferRect.centerY())
564
+ matrix.setRectToRect(viewRect, bufferRect, Matrix.ScaleToFit.FILL)
565
+ val scale = max(
566
+ viewHeight / preview.height.toFloat(),
567
+ viewWidth / preview.width.toFloat()
568
+ )
595
569
  matrix.postScale(scale, scale, centerX, centerY)
570
+ val rotateDegrees = if (rotation == Surface.ROTATION_90) -90f else 90f
571
+ matrix.postRotate(rotateDegrees, centerX, centerY)
572
+ } else if (rotation == Surface.ROTATION_180) {
573
+ matrix.postRotate(180f, centerX, centerY)
596
574
  }
597
575
 
598
576
  previewView.setTransform(matrix)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-rectangle-doc-scanner",
3
- "version": "7.10.0",
3
+ "version": "7.11.0",
4
4
  "description": "Native-backed document scanner for React Native with customizable overlays.",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",