react-native-rectangle-doc-scanner 3.200.0 → 3.201.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.
|
@@ -22,6 +22,7 @@ import android.os.Handler
|
|
|
22
22
|
import android.os.HandlerThread
|
|
23
23
|
import android.util.Log
|
|
24
24
|
import android.util.Size
|
|
25
|
+
import android.view.Gravity
|
|
25
26
|
import android.view.Surface
|
|
26
27
|
import android.view.TextureView
|
|
27
28
|
import androidx.core.content.ContextCompat
|
|
@@ -359,6 +360,8 @@ class CameraController(
|
|
|
359
360
|
|
|
360
361
|
private fun updatePreviewTransform() {
|
|
361
362
|
val previewSize = previewSize ?: return
|
|
363
|
+
adjustPreviewLayout(previewSize)
|
|
364
|
+
|
|
362
365
|
val viewWidth = previewView.width
|
|
363
366
|
val viewHeight = previewView.height
|
|
364
367
|
if (viewWidth == 0 || viewHeight == 0) {
|
|
@@ -396,6 +399,45 @@ class CameraController(
|
|
|
396
399
|
previewView.setTransform(matrix)
|
|
397
400
|
}
|
|
398
401
|
|
|
402
|
+
private fun adjustPreviewLayout(previewSize: Size) {
|
|
403
|
+
val parentView = previewView.parent as? android.view.View ?: return
|
|
404
|
+
val parentWidth = parentView.width
|
|
405
|
+
val parentHeight = parentView.height
|
|
406
|
+
if (parentWidth == 0 || parentHeight == 0) {
|
|
407
|
+
return
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
val rotationDegrees = getRotationDegrees()
|
|
411
|
+
val bufferWidth = previewSize.width.toFloat()
|
|
412
|
+
val bufferHeight = previewSize.height.toFloat()
|
|
413
|
+
val bufferAspect = if (rotationDegrees == 90 || rotationDegrees == 270) {
|
|
414
|
+
bufferHeight / bufferWidth
|
|
415
|
+
} else {
|
|
416
|
+
bufferWidth / bufferHeight
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
val parentAspect = parentWidth.toFloat() / parentHeight.toFloat()
|
|
420
|
+
val targetWidth: Int
|
|
421
|
+
val targetHeight: Int
|
|
422
|
+
|
|
423
|
+
if (parentAspect > bufferAspect) {
|
|
424
|
+
targetHeight = parentHeight
|
|
425
|
+
targetWidth = (parentHeight * bufferAspect).toInt()
|
|
426
|
+
} else {
|
|
427
|
+
targetWidth = parentWidth
|
|
428
|
+
targetHeight = (parentWidth / bufferAspect).toInt()
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
val layoutParams = (previewView.layoutParams as? android.widget.FrameLayout.LayoutParams)
|
|
432
|
+
?: android.widget.FrameLayout.LayoutParams(targetWidth, targetHeight)
|
|
433
|
+
if (layoutParams.width != targetWidth || layoutParams.height != targetHeight) {
|
|
434
|
+
layoutParams.width = targetWidth
|
|
435
|
+
layoutParams.height = targetHeight
|
|
436
|
+
layoutParams.gravity = Gravity.CENTER
|
|
437
|
+
previewView.layoutParams = layoutParams
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
|
|
399
441
|
private fun handleImage(image: Image) {
|
|
400
442
|
try {
|
|
401
443
|
val rotationDegrees = getRotationDegrees()
|
package/package.json
CHANGED