react-native-rectangle-doc-scanner 3.199.0 → 3.200.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.
@@ -366,25 +366,32 @@ class CameraController(
366
366
  }
367
367
 
368
368
  val rotationDegrees = getRotationDegrees()
369
- val matrix = Matrix()
370
- val viewRect = RectF(0f, 0f, viewWidth.toFloat(), viewHeight.toFloat())
371
- val bufferRect = if (rotationDegrees == 90 || rotationDegrees == 270) {
372
- RectF(0f, 0f, previewSize.height.toFloat(), previewSize.width.toFloat())
369
+ val bufferWidth = previewSize.width.toFloat()
370
+ val bufferHeight = previewSize.height.toFloat()
371
+ val rotatedBufferWidth = if (rotationDegrees == 90 || rotationDegrees == 270) {
372
+ bufferHeight
373
+ } else {
374
+ bufferWidth
375
+ }
376
+ val rotatedBufferHeight = if (rotationDegrees == 90 || rotationDegrees == 270) {
377
+ bufferWidth
373
378
  } else {
374
- RectF(0f, 0f, previewSize.width.toFloat(), previewSize.height.toFloat())
379
+ bufferHeight
375
380
  }
376
- val centerX = viewRect.centerX()
377
- val centerY = viewRect.centerY()
378
381
 
379
- bufferRect.offset(centerX - bufferRect.centerX(), centerY - bufferRect.centerY())
380
- // Fit entire buffer into view (no crop).
381
- matrix.setRectToRect(bufferRect, viewRect, Matrix.ScaleToFit.CENTER)
382
+ val scale = kotlin.math.min(
383
+ viewWidth.toFloat() / rotatedBufferWidth,
384
+ viewHeight.toFloat() / rotatedBufferHeight
385
+ )
382
386
 
383
- when (rotationDegrees) {
384
- 90 -> matrix.postRotate(90f, centerX, centerY)
385
- 180 -> matrix.postRotate(180f, centerX, centerY)
386
- 270 -> matrix.postRotate(270f, centerX, centerY)
387
+ val matrix = Matrix()
388
+ // Center buffer at origin, rotate, scale to fit, then move to view center.
389
+ matrix.postTranslate(-bufferWidth / 2f, -bufferHeight / 2f)
390
+ if (rotationDegrees != 0) {
391
+ matrix.postRotate(rotationDegrees.toFloat())
387
392
  }
393
+ matrix.postScale(scale, scale)
394
+ matrix.postTranslate(viewWidth / 2f, viewHeight / 2f)
388
395
 
389
396
  previewView.setTransform(matrix)
390
397
  }
@@ -517,7 +524,11 @@ class CameraController(
517
524
 
518
525
  val ratioFiltered = if (targetRatio != null) {
519
526
  candidates.filter { size ->
520
- val ratio = size.width.toFloat() / size.height.toFloat()
527
+ val ratio = if (targetRatio < 1f) {
528
+ size.height.toFloat() / size.width.toFloat()
529
+ } else {
530
+ size.width.toFloat() / size.height.toFloat()
531
+ }
521
532
  kotlin.math.abs(ratio - targetRatio) <= 0.05f
522
533
  }
523
534
  } else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-rectangle-doc-scanner",
3
- "version": "3.199.0",
3
+ "version": "3.200.0",
4
4
  "description": "Native-backed document scanner for React Native with customizable overlays.",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",