react-native-rectangle-doc-scanner 3.195.0 → 3.197.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.
@@ -8,6 +8,7 @@ import android.graphics.BitmapFactory
8
8
  import android.graphics.ImageFormat
9
9
  import android.graphics.Matrix
10
10
  import android.graphics.Rect
11
+ import android.graphics.RectF
11
12
  import android.graphics.SurfaceTexture
12
13
  import android.graphics.YuvImage
13
14
  import android.hardware.camera2.CameraCaptureSession
@@ -80,6 +81,7 @@ class CameraController(
80
81
 
81
82
  override fun onSurfaceTextureSizeChanged(surface: SurfaceTexture, width: Int, height: Int) {
82
83
  Log.d(TAG, "[CAMERA2] Texture size changed: ${width}x${height}")
84
+ updatePreviewTransform()
83
85
  }
84
86
 
85
87
  override fun onSurfaceTextureDestroyed(surface: SurfaceTexture): Boolean {
@@ -330,6 +332,7 @@ class CameraController(
330
332
  try {
331
333
  session.setRepeatingRequest(previewRequestBuilder!!.build(), null, backgroundHandler)
332
334
  Log.d(TAG, "[CAMERA2] Preview session started")
335
+ updatePreviewTransform()
333
336
  } catch (e: Exception) {
334
337
  Log.e(TAG, "[CAMERA2] Failed to start preview", e)
335
338
  }
@@ -346,6 +349,44 @@ class CameraController(
346
349
  }
347
350
  }
348
351
 
352
+ private fun updatePreviewTransform() {
353
+ val previewSize = previewSize ?: return
354
+ val viewWidth = previewView.width
355
+ val viewHeight = previewView.height
356
+ if (viewWidth == 0 || viewHeight == 0) {
357
+ return
358
+ }
359
+
360
+ val rotationDegrees = getRotationDegrees()
361
+ val matrix = Matrix()
362
+ val viewRect = RectF(0f, 0f, viewWidth.toFloat(), viewHeight.toFloat())
363
+ val bufferRect = if (rotationDegrees == 90 || rotationDegrees == 270) {
364
+ RectF(0f, 0f, previewSize.height.toFloat(), previewSize.width.toFloat())
365
+ } else {
366
+ RectF(0f, 0f, previewSize.width.toFloat(), previewSize.height.toFloat())
367
+ }
368
+ val centerX = viewRect.centerX()
369
+ val centerY = viewRect.centerY()
370
+
371
+ bufferRect.offset(centerX - bufferRect.centerX(), centerY - bufferRect.centerY())
372
+ matrix.setRectToRect(viewRect, bufferRect, Matrix.ScaleToFit.FILL)
373
+
374
+ val scale = if (rotationDegrees == 90 || rotationDegrees == 270) {
375
+ maxOf(viewHeight.toFloat() / previewSize.height, viewWidth.toFloat() / previewSize.width)
376
+ } else {
377
+ maxOf(viewWidth.toFloat() / previewSize.width, viewHeight.toFloat() / previewSize.height)
378
+ }
379
+ matrix.postScale(scale, scale, centerX, centerY)
380
+
381
+ when (rotationDegrees) {
382
+ 90 -> matrix.postRotate(90f, centerX, centerY)
383
+ 180 -> matrix.postRotate(180f, centerX, centerY)
384
+ 270 -> matrix.postRotate(270f, centerX, centerY)
385
+ }
386
+
387
+ previewView.setTransform(matrix)
388
+ }
389
+
349
390
  private fun handleImage(image: Image) {
350
391
  try {
351
392
  val rotationDegrees = getRotationDegrees()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-rectangle-doc-scanner",
3
- "version": "3.195.0",
3
+ "version": "3.197.0",
4
4
  "description": "Native-backed document scanner for React Native with customizable overlays.",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",