react-native-rectangle-doc-scanner 7.33.0 → 7.34.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.
@@ -249,7 +249,8 @@ class CameraController(
249
249
  // Prefer 4:3 to match iOS FOV on phones; use view aspect on tablets to reduce crop.
250
250
  val isTablet = context.resources.configuration.smallestScreenWidthDp >= 600
251
251
  val targetPreviewAspect = if (isTablet) viewAspect else 4.0 / 3.0
252
- previewSize = chooseBestSize(previewSizes, targetPreviewAspect, null, preferClosestAspect = true)
252
+ val minPreviewArea = if (isTablet) 1280 * 720 else 960 * 720
253
+ previewSize = chooseBestSize(previewSizes, targetPreviewAspect, null, minPreviewArea, preferClosestAspect = true)
253
254
  ?: chooseBestSize(previewSizes, viewAspect, null, preferClosestAspect = true)
254
255
  ?: previewSizes?.maxByOrNull { it.width * it.height }
255
256
  Log.d(TAG, "[CAMERA2] Selected preview size: ${previewSize?.width}x${previewSize?.height}")
@@ -593,6 +594,7 @@ class CameraController(
593
594
  sizes: Array<Size>?,
594
595
  targetAspect: Double,
595
596
  maxArea: Int?,
597
+ minArea: Int? = null,
596
598
  preferClosestAspect: Boolean = false
597
599
  ): Size? {
598
600
  if (sizes == null || sizes.isEmpty()) return null
@@ -608,6 +610,14 @@ class CameraController(
608
610
  return sorted.first()
609
611
  }
610
612
 
613
+ val minCapped = if (minArea != null) {
614
+ capped.filter { it.width * it.height >= minArea }
615
+ } else {
616
+ capped
617
+ }
618
+
619
+ val poolForSelection = if (minCapped.isNotEmpty()) minCapped else capped
620
+
611
621
  fun aspectDiff(size: Size): Double {
612
622
  val w = size.width.toDouble()
613
623
  val h = size.height.toDouble()
@@ -617,26 +627,22 @@ class CameraController(
617
627
  }
618
628
 
619
629
  if (preferClosestAspect) {
620
- // Avoid tiny preview sizes even if aspect matches; prefer reasonable resolution.
621
- val minAcceptableArea = 640 * 480
622
- val pool = capped.filter { it.width * it.height >= minAcceptableArea }.ifEmpty { capped }
623
-
624
630
  // Prefer aspect ratio match first, then pick the highest resolution among matches.
625
- pool.forEach { size ->
631
+ poolForSelection.forEach { size ->
626
632
  val diff = aspectDiff(size)
627
633
  Log.d(TAG, "[SIZE_SELECTION] ${size.width}x${size.height} aspect=${size.width.toDouble()/size.height} diff=$diff")
628
634
  }
629
635
 
630
- val bestDiff = pool.minOf { aspectDiff(it) }
631
- val close = pool.filter { aspectDiff(it) <= bestDiff + 0.001 }
632
- val selected = close.maxByOrNull { it.width * it.height } ?: pool.maxByOrNull { it.width * it.height }
636
+ val bestDiff = poolForSelection.minOf { aspectDiff(it) }
637
+ val close = poolForSelection.filter { aspectDiff(it) <= bestDiff + 0.001 }
638
+ val selected = close.maxByOrNull { it.width * it.height } ?: poolForSelection.maxByOrNull { it.width * it.height }
633
639
  Log.d(TAG, "[SIZE_SELECTION] Best aspect diff: $bestDiff, candidates: ${close.size}, selected: ${selected?.width}x${selected?.height}")
634
640
  return selected
635
641
  }
636
642
 
637
- val matching = capped.filter { aspectDiff(it) <= ANALYSIS_ASPECT_TOLERANCE }
643
+ val matching = poolForSelection.filter { aspectDiff(it) <= ANALYSIS_ASPECT_TOLERANCE }
638
644
 
639
- return matching.firstOrNull() ?: capped.first()
645
+ return matching.firstOrNull() ?: poolForSelection.first()
640
646
  }
641
647
 
642
648
  private fun rotateAndMirror(bitmap: Bitmap, rotationDegrees: Int, mirror: Boolean): Bitmap {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-rectangle-doc-scanner",
3
- "version": "7.33.0",
3
+ "version": "7.34.0",
4
4
  "description": "Native-backed document scanner for React Native with customizable overlays.",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",