react-native-rectangle-doc-scanner 3.201.0 → 3.202.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.
|
@@ -44,6 +44,7 @@ class CameraController(
|
|
|
44
44
|
private var imageReader: ImageReader? = null
|
|
45
45
|
private var backgroundThread: HandlerThread? = null
|
|
46
46
|
private var backgroundHandler: Handler? = null
|
|
47
|
+
private var previewLayoutListener: android.view.View.OnLayoutChangeListener? = null
|
|
47
48
|
|
|
48
49
|
private var cameraId: String? = null
|
|
49
50
|
private var sensorOrientation: Int = 0
|
|
@@ -62,8 +63,8 @@ class CameraController(
|
|
|
62
63
|
|
|
63
64
|
companion object {
|
|
64
65
|
private const val TAG = "CameraController"
|
|
65
|
-
private const val MAX_PREVIEW_WIDTH =
|
|
66
|
-
private const val MAX_PREVIEW_HEIGHT =
|
|
66
|
+
private const val MAX_PREVIEW_WIDTH = 1920
|
|
67
|
+
private const val MAX_PREVIEW_HEIGHT = 1440
|
|
67
68
|
}
|
|
68
69
|
|
|
69
70
|
private data class LastFrame(
|
|
@@ -121,6 +122,13 @@ class CameraController(
|
|
|
121
122
|
startBackgroundThread()
|
|
122
123
|
chooseCamera()
|
|
123
124
|
|
|
125
|
+
if (previewLayoutListener == null) {
|
|
126
|
+
previewLayoutListener = android.view.View.OnLayoutChangeListener { _, _, _, _, _, _, _, _, _ ->
|
|
127
|
+
updatePreviewTransform()
|
|
128
|
+
}
|
|
129
|
+
previewView.addOnLayoutChangeListener(previewLayoutListener)
|
|
130
|
+
}
|
|
131
|
+
|
|
124
132
|
if (previewView.isAvailable) {
|
|
125
133
|
openCamera()
|
|
126
134
|
} else {
|
|
@@ -130,6 +138,10 @@ class CameraController(
|
|
|
130
138
|
|
|
131
139
|
fun stopCamera() {
|
|
132
140
|
Log.d(TAG, "[CAMERA2] stopCamera called")
|
|
141
|
+
previewLayoutListener?.let { listener ->
|
|
142
|
+
previewView.removeOnLayoutChangeListener(listener)
|
|
143
|
+
}
|
|
144
|
+
previewLayoutListener = null
|
|
133
145
|
try {
|
|
134
146
|
captureSession?.close()
|
|
135
147
|
captureSession = null
|
|
@@ -564,21 +576,24 @@ class CameraController(
|
|
|
564
576
|
val maxCandidates = choices.filter { it.width <= maxWidth && it.height <= maxHeight }
|
|
565
577
|
val candidates = if (maxCandidates.isNotEmpty()) maxCandidates else choices.toList()
|
|
566
578
|
|
|
567
|
-
|
|
568
|
-
candidates.
|
|
569
|
-
|
|
579
|
+
if (targetRatio == null) {
|
|
580
|
+
return candidates.sortedBy { it.width * it.height }.last()
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
val normalizedTarget = targetRatio
|
|
584
|
+
val sorted = candidates.sortedWith(
|
|
585
|
+
compareBy<Size> { size ->
|
|
586
|
+
val ratio = if (normalizedTarget < 1f) {
|
|
570
587
|
size.height.toFloat() / size.width.toFloat()
|
|
571
588
|
} else {
|
|
572
589
|
size.width.toFloat() / size.height.toFloat()
|
|
573
590
|
}
|
|
574
|
-
kotlin.math.abs(ratio -
|
|
591
|
+
kotlin.math.abs(ratio - normalizedTarget)
|
|
592
|
+
}.thenByDescending { size ->
|
|
593
|
+
size.width * size.height
|
|
575
594
|
}
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
}
|
|
579
|
-
|
|
580
|
-
val pickFrom = if (ratioFiltered.isNotEmpty()) ratioFiltered else candidates
|
|
581
|
-
return pickFrom.sortedBy { it.width * it.height }.last()
|
|
595
|
+
)
|
|
596
|
+
return sorted.first()
|
|
582
597
|
}
|
|
583
598
|
|
|
584
599
|
private fun startBackgroundThread() {
|
package/package.json
CHANGED