react-native-rectangle-doc-scanner 3.202.0 → 3.203.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.
@@ -50,6 +50,8 @@ class CameraController(
50
50
  private var sensorOrientation: Int = 0
51
51
  private var previewSize: Size? = null
52
52
  private var analysisSize: Size? = null
53
+ private var previewChoices: Array<Size> = emptyArray()
54
+ private var analysisChoices: Array<Size> = emptyArray()
53
55
  private var useFrontCamera = false
54
56
  private var torchEnabled = false
55
57
  private var detectionEnabled = true
@@ -63,7 +65,7 @@ class CameraController(
63
65
 
64
66
  companion object {
65
67
  private const val TAG = "CameraController"
66
- private const val MAX_PREVIEW_WIDTH = 1920
68
+ private const val MAX_PREVIEW_WIDTH = 2560
67
69
  private const val MAX_PREVIEW_HEIGHT = 1440
68
70
  }
69
71
 
@@ -254,8 +256,8 @@ class CameraController(
254
256
  sensorOrientation = characteristics.get(CameraCharacteristics.SENSOR_ORIENTATION) ?: 0
255
257
 
256
258
  val streamConfig = characteristics.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP)
257
- val previewChoices = streamConfig?.getOutputSizes(SurfaceTexture::class.java) ?: emptyArray()
258
- val analysisChoices = streamConfig?.getOutputSizes(ImageFormat.YUV_420_888) ?: emptyArray()
259
+ previewChoices = streamConfig?.getOutputSizes(SurfaceTexture::class.java) ?: emptyArray()
260
+ analysisChoices = streamConfig?.getOutputSizes(ImageFormat.YUV_420_888) ?: emptyArray()
259
261
 
260
262
  val viewWidth = if (previewView.width > 0) previewView.width else context.resources.displayMetrics.widthPixels
261
263
  val viewHeight = if (previewView.height > 0) previewView.height else context.resources.displayMetrics.heightPixels
@@ -314,8 +316,9 @@ class CameraController(
314
316
  private fun createPreviewSession() {
315
317
  val device = cameraDevice ?: return
316
318
  val texture = previewView.surfaceTexture ?: return
317
- val previewSize = previewSize ?: return
318
- val analysisSize = analysisSize ?: previewSize
319
+ val sizes = ensurePreviewSizes()
320
+ val previewSize = sizes.first ?: return
321
+ val analysisSize = sizes.second ?: previewSize
319
322
 
320
323
  texture.setDefaultBufferSize(previewSize.width, previewSize.height)
321
324
  val previewSurface = Surface(texture)
@@ -370,6 +373,32 @@ class CameraController(
370
373
  }
371
374
  }
372
375
 
376
+ private fun ensurePreviewSizes(): Pair<Size?, Size?> {
377
+ if (previewChoices.isEmpty()) {
378
+ return Pair(previewSize, analysisSize)
379
+ }
380
+
381
+ val viewWidth = if (previewView.width > 0) previewView.width else context.resources.displayMetrics.widthPixels
382
+ val viewHeight = if (previewView.height > 0) previewView.height else context.resources.displayMetrics.heightPixels
383
+ val targetRatio = if (viewWidth > 0 && viewHeight > 0) {
384
+ viewWidth.toFloat() / viewHeight.toFloat()
385
+ } else {
386
+ null
387
+ }
388
+
389
+ val newPreview = chooseSize(previewChoices, MAX_PREVIEW_WIDTH, MAX_PREVIEW_HEIGHT, targetRatio)
390
+ val newAnalysis = chooseSize(analysisChoices, MAX_PREVIEW_WIDTH, MAX_PREVIEW_HEIGHT, targetRatio)
391
+
392
+ if (newPreview != null && newPreview != previewSize) {
393
+ previewSize = newPreview
394
+ }
395
+ if (newAnalysis != null && newAnalysis != analysisSize) {
396
+ analysisSize = newAnalysis
397
+ }
398
+
399
+ return Pair(previewSize, analysisSize)
400
+ }
401
+
373
402
  private fun updatePreviewTransform() {
374
403
  val previewSize = previewSize ?: return
375
404
  adjustPreviewLayout(previewSize)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-rectangle-doc-scanner",
3
- "version": "3.202.0",
3
+ "version": "3.203.0",
4
4
  "description": "Native-backed document scanner for React Native with customizable overlays.",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",