react-native-rectangle-doc-scanner 4.4.0 → 4.5.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.
@@ -227,6 +227,13 @@ class CameraController(
227
227
  ?: captureSizes?.maxByOrNull { it.width * it.height }
228
228
 
229
229
  setupImageReaders()
230
+ Log.d(
231
+ TAG,
232
+ "[CAMERA2] view=${previewView.width}x${previewView.height} " +
233
+ "preview=${previewSize?.width}x${previewSize?.height} " +
234
+ "analysis=${analysisSize?.width}x${analysisSize?.height} " +
235
+ "capture=${captureSize?.width}x${captureSize?.height}"
236
+ )
230
237
 
231
238
  if (ContextCompat.checkSelfPermission(context, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
232
239
  Log.e(TAG, "[CAMERA2] Camera permission not granted")
@@ -130,6 +130,13 @@ class DocumentScannerView(context: ThemedReactContext) : FrameLayout(context), L
130
130
  initializeCameraWhenReady()
131
131
  }
132
132
 
133
+ override fun onLayout(changed: Boolean, left: Int, top: Int, right: Int, bottom: Int) {
134
+ super.onLayout(changed, left, top, right, bottom)
135
+ if (changed) {
136
+ Log.d(TAG, "[LAYOUT] View size: ${right - left}x${bottom - top}, PreviewView: ${previewView.width}x${previewView.height}")
137
+ }
138
+ }
139
+
133
140
  private fun initializeCameraWhenReady() {
134
141
  // If view is already laid out, start camera immediately
135
142
  if (width > 0 && height > 0) {
@@ -384,13 +391,23 @@ class DocumentScannerView(context: ThemedReactContext) : FrameLayout(context), L
384
391
  shouldCrop = shouldCrop
385
392
  )
386
393
 
387
- // Save or encode images
388
- val result = if (useBase64) {
389
- Arguments.createMap().apply {
390
- putString("croppedImage", ImageProcessor.bitmapToBase64(processed.croppedImage, quality))
391
- putString("initialImage", ImageProcessor.bitmapToBase64(processed.initialImage, quality))
392
- putMap("rectangleCoordinates", detectedRectangle?.toMap()?.toWritableMap())
394
+ fun buildResult(
395
+ croppedPath: String,
396
+ initialPath: String,
397
+ rectangle: Rectangle?
398
+ ): WritableMap {
399
+ return Arguments.createMap().apply {
400
+ putString("croppedImage", croppedPath)
401
+ putString("initialImage", initialPath)
402
+ putMap("rectangleCoordinates", rectangle?.toMap()?.toWritableMap())
393
403
  }
404
+ }
405
+
406
+ val (resultForPromise, resultForEvent) = if (useBase64) {
407
+ val croppedBase64 = ImageProcessor.bitmapToBase64(processed.croppedImage, quality)
408
+ val initialBase64 = ImageProcessor.bitmapToBase64(processed.initialImage, quality)
409
+ buildResult(croppedBase64, initialBase64, detectedRectangle) to
410
+ buildResult(croppedBase64, initialBase64, detectedRectangle)
394
411
  } else {
395
412
  val timestamp = System.currentTimeMillis()
396
413
  val croppedPath = ImageProcessor.saveBitmapToFile(
@@ -405,22 +422,18 @@ class DocumentScannerView(context: ThemedReactContext) : FrameLayout(context), L
405
422
  "initial_img_$timestamp.jpeg",
406
423
  quality
407
424
  )
408
-
409
- Arguments.createMap().apply {
410
- putString("croppedImage", croppedPath)
411
- putString("initialImage", initialPath)
412
- putMap("rectangleCoordinates", detectedRectangle?.toMap()?.toWritableMap())
413
- }
425
+ buildResult(croppedPath, initialPath, detectedRectangle) to
426
+ buildResult(croppedPath, initialPath, detectedRectangle)
414
427
  }
415
428
 
416
429
  withContext(Dispatchers.Main) {
417
430
  Log.d(TAG, "Processing completed, resolving promise: ${promise != null}")
418
431
 
419
432
  // Resolve promise first (if provided) - matches iOS behavior
420
- promise?.resolve(result)
433
+ promise?.resolve(resultForPromise)
421
434
 
422
435
  // Then send event for backwards compatibility
423
- sendPictureTakenEvent(result)
436
+ sendPictureTakenEvent(resultForEvent)
424
437
 
425
438
  isCapturing = false
426
439
 
@@ -442,9 +455,8 @@ class DocumentScannerView(context: ThemedReactContext) : FrameLayout(context), L
442
455
  }
443
456
 
444
457
  private fun sendPictureTakenEvent(data: WritableMap) {
445
- val event = data.toHashMap().toWritableMap()
446
458
  themedContext.getJSModule(RCTEventEmitter::class.java)
447
- .receiveEvent(id, "onPictureTaken", event)
459
+ .receiveEvent(id, "onPictureTaken", data)
448
460
  }
449
461
 
450
462
  private fun sendRectangleDetectEvent(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-rectangle-doc-scanner",
3
- "version": "4.4.0",
3
+ "version": "4.5.0",
4
4
  "description": "Native-backed document scanner for React Native with customizable overlays.",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",