react-native-rectangle-doc-scanner 15.2.0 → 15.3.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.
@@ -483,6 +483,35 @@ const FullDocScanner = ({ onResult, onClose, detectionConfig, overlayColor = '#3
483
483
  resetScannerView,
484
484
  usesAndroidScannerActivity,
485
485
  ]);
486
+ const startAndroidScan = (0, react_1.useCallback)(async () => {
487
+ if (!usesAndroidScannerActivity || !pdfScannerManager?.startDocumentScanner) {
488
+ throw new Error('document_scanner_not_available');
489
+ }
490
+ if (captureInProgressRef.current) {
491
+ throw new Error('capture_in_progress');
492
+ }
493
+ captureInProgressRef.current = true;
494
+ captureModeRef.current = 'grid';
495
+ try {
496
+ const payload = await pdfScannerManager.startDocumentScanner({ pageLimit: 2 });
497
+ const normalizedPath = stripFileUri(payload?.initialImage ?? payload?.croppedImage ?? '');
498
+ const capturePayload = {
499
+ path: normalizedPath,
500
+ initialPath: payload?.initialImage ? stripFileUri(payload.initialImage) : normalizedPath,
501
+ croppedPath: payload?.croppedImage ? stripFileUri(payload.croppedImage) : normalizedPath,
502
+ quad: null,
503
+ rectangle: null,
504
+ width: payload?.width ?? 0,
505
+ height: payload?.height ?? 0,
506
+ origin: 'manual',
507
+ pages: payload?.pages ?? null,
508
+ };
509
+ await handleCapture(capturePayload);
510
+ }
511
+ finally {
512
+ captureInProgressRef.current = false;
513
+ }
514
+ }, [handleCapture, pdfScannerManager, usesAndroidScannerActivity]);
486
515
  const triggerManualCapture = (0, react_1.useCallback)(() => {
487
516
  const scannerInstance = docScannerRef.current;
488
517
  const hasScanner = !!scannerInstance;
@@ -508,6 +537,19 @@ const FullDocScanner = ({ onResult, onClose, detectionConfig, overlayColor = '#3
508
537
  return;
509
538
  }
510
539
  if (!hasScanner) {
540
+ if (usesAndroidScannerActivity) {
541
+ startAndroidScan().catch((error) => {
542
+ const errorMessage = error instanceof Error ? error.message : String(error);
543
+ console.error('[FullDocScanner] Android scan failed:', errorMessage, error);
544
+ if (errorMessage.includes('SCAN_CANCELLED')) {
545
+ resetScannerView({ remount: true });
546
+ onClose?.();
547
+ return;
548
+ }
549
+ emitError(error instanceof Error ? error : new Error(String(error)), 'Failed to capture image. Please try again.');
550
+ });
551
+ return;
552
+ }
511
553
  console.error('[FullDocScanner] DocScanner ref not available');
512
554
  return;
513
555
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-rectangle-doc-scanner",
3
- "version": "15.2.0",
3
+ "version": "15.3.0",
4
4
  "description": "Native-backed document scanner for React Native with customizable overlays.",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",
@@ -654,6 +654,40 @@ export const FullDocScanner: React.FC<FullDocScannerProps> = ({
654
654
  ],
655
655
  );
656
656
 
657
+ const startAndroidScan = useCallback(async () => {
658
+ if (!usesAndroidScannerActivity || !pdfScannerManager?.startDocumentScanner) {
659
+ throw new Error('document_scanner_not_available');
660
+ }
661
+
662
+ if (captureInProgressRef.current) {
663
+ throw new Error('capture_in_progress');
664
+ }
665
+
666
+ captureInProgressRef.current = true;
667
+ captureModeRef.current = 'grid';
668
+
669
+ try {
670
+ const payload = await pdfScannerManager.startDocumentScanner({ pageLimit: 2 });
671
+ const normalizedPath = stripFileUri(payload?.initialImage ?? payload?.croppedImage ?? '');
672
+
673
+ const capturePayload: DocScannerCapture = {
674
+ path: normalizedPath,
675
+ initialPath: payload?.initialImage ? stripFileUri(payload.initialImage) : normalizedPath,
676
+ croppedPath: payload?.croppedImage ? stripFileUri(payload.croppedImage) : normalizedPath,
677
+ quad: null,
678
+ rectangle: null,
679
+ width: payload?.width ?? 0,
680
+ height: payload?.height ?? 0,
681
+ origin: 'manual',
682
+ pages: payload?.pages ?? null,
683
+ };
684
+
685
+ await handleCapture(capturePayload);
686
+ } finally {
687
+ captureInProgressRef.current = false;
688
+ }
689
+ }, [handleCapture, pdfScannerManager, usesAndroidScannerActivity]);
690
+
657
691
  const triggerManualCapture = useCallback(() => {
658
692
  const scannerInstance = docScannerRef.current;
659
693
  const hasScanner = !!scannerInstance;
@@ -683,6 +717,22 @@ export const FullDocScanner: React.FC<FullDocScannerProps> = ({
683
717
  }
684
718
 
685
719
  if (!hasScanner) {
720
+ if (usesAndroidScannerActivity) {
721
+ startAndroidScan().catch((error: unknown) => {
722
+ const errorMessage = error instanceof Error ? error.message : String(error);
723
+ console.error('[FullDocScanner] Android scan failed:', errorMessage, error);
724
+ if (errorMessage.includes('SCAN_CANCELLED')) {
725
+ resetScannerView({ remount: true });
726
+ onClose?.();
727
+ return;
728
+ }
729
+ emitError(
730
+ error instanceof Error ? error : new Error(String(error)),
731
+ 'Failed to capture image. Please try again.',
732
+ );
733
+ });
734
+ return;
735
+ }
686
736
  console.error('[FullDocScanner] DocScanner ref not available');
687
737
  return;
688
738
  }