react-native-rectangle-doc-scanner 3.51.0 → 3.53.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.
- package/dist/FullDocScanner.d.ts +0 -1
- package/dist/FullDocScanner.js +22 -7
- package/package.json +1 -1
- package/src/FullDocScanner.tsx +31 -10
package/dist/FullDocScanner.d.ts
CHANGED
package/dist/FullDocScanner.js
CHANGED
|
@@ -53,7 +53,7 @@ const normalizeCapturedDocument = (document) => {
|
|
|
53
53
|
croppedPath: document.croppedPath ? stripFileUri(document.croppedPath) : null,
|
|
54
54
|
};
|
|
55
55
|
};
|
|
56
|
-
const FullDocScanner = ({ onResult, onClose, detectionConfig, overlayColor = '#3170f3', gridColor, gridLineWidth, showGrid, strings,
|
|
56
|
+
const FullDocScanner = ({ onResult, onClose, detectionConfig, overlayColor = '#3170f3', gridColor, gridLineWidth, showGrid, strings, minStableFrames, onError, enableGallery = true, cropWidth = 1200, cropHeight = 1600, }) => {
|
|
57
57
|
const [processing, setProcessing] = (0, react_1.useState)(false);
|
|
58
58
|
const [croppedImageData, setCroppedImageData] = (0, react_1.useState)(null);
|
|
59
59
|
const [isGalleryOpen, setIsGalleryOpen] = (0, react_1.useState)(false);
|
|
@@ -122,10 +122,14 @@ const FullDocScanner = ({ onResult, onClose, detectionConfig, overlayColor = '#3
|
|
|
122
122
|
initialPath: document.initialPath,
|
|
123
123
|
captureMode: captureModeRef.current,
|
|
124
124
|
});
|
|
125
|
+
if (document.origin === 'auto') {
|
|
126
|
+
console.log('[FullDocScanner] Ignoring auto capture result');
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
125
129
|
const captureMode = captureModeRef.current;
|
|
126
|
-
// Ignore auto captures - only process manual captures
|
|
127
130
|
if (!captureMode) {
|
|
128
|
-
console.
|
|
131
|
+
console.warn('[FullDocScanner] Missing capture mode for manual capture result');
|
|
132
|
+
captureModeRef.current = null;
|
|
129
133
|
return;
|
|
130
134
|
}
|
|
131
135
|
captureModeRef.current = null;
|
|
@@ -229,9 +233,20 @@ const FullDocScanner = ({ onResult, onClose, detectionConfig, overlayColor = '#3
|
|
|
229
233
|
}
|
|
230
234
|
}, []);
|
|
231
235
|
const handleRectangleDetect = (0, react_1.useCallback)((event) => {
|
|
232
|
-
|
|
233
|
-
const
|
|
234
|
-
|
|
236
|
+
const stableCounter = event.stableCounter ?? 0;
|
|
237
|
+
const hasRectangle = Boolean(event.rectangleOnScreen ?? event.rectangleCoordinates);
|
|
238
|
+
const isGoodRectangle = event.lastDetectionType === 0 && hasRectangle && stableCounter > 0;
|
|
239
|
+
setRectangleDetected((prev) => {
|
|
240
|
+
if (prev !== isGoodRectangle) {
|
|
241
|
+
console.log('[FullDocScanner] Rectangle detection update', {
|
|
242
|
+
lastDetectionType: event.lastDetectionType,
|
|
243
|
+
stableCounter,
|
|
244
|
+
hasRectangle,
|
|
245
|
+
isGoodRectangle,
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
return isGoodRectangle;
|
|
249
|
+
});
|
|
235
250
|
}, []);
|
|
236
251
|
return (react_1.default.createElement(react_native_1.View, { style: styles.container },
|
|
237
252
|
croppedImageData ? (
|
|
@@ -243,7 +258,7 @@ const FullDocScanner = ({ onResult, onClose, detectionConfig, overlayColor = '#3
|
|
|
243
258
|
react_1.default.createElement(react_native_1.Text, { style: styles.confirmButtonText }, mergedStrings.retake)),
|
|
244
259
|
react_1.default.createElement(react_native_1.TouchableOpacity, { style: [styles.confirmButton, styles.confirmButtonPrimary], onPress: handleConfirm, accessibilityLabel: mergedStrings.confirm, accessibilityRole: "button" },
|
|
245
260
|
react_1.default.createElement(react_native_1.Text, { style: styles.confirmButtonText }, mergedStrings.confirm))))) : (react_1.default.createElement(react_native_1.View, { style: styles.flex },
|
|
246
|
-
react_1.default.createElement(DocScanner_1.DocScanner, { ref: docScannerRef, autoCapture:
|
|
261
|
+
react_1.default.createElement(DocScanner_1.DocScanner, { ref: docScannerRef, autoCapture: true, overlayColor: overlayColor, showGrid: showGrid, gridColor: resolvedGridColor, gridLineWidth: gridLineWidth, minStableFrames: minStableFrames ?? 6, detectionConfig: detectionConfig, onCapture: handleCapture, onRectangleDetect: handleRectangleDetect, showManualCaptureButton: false },
|
|
247
262
|
react_1.default.createElement(react_native_1.View, { style: styles.overlayTop, pointerEvents: "box-none" },
|
|
248
263
|
react_1.default.createElement(react_native_1.TouchableOpacity, { style: styles.closeButton, onPress: handleClose, accessibilityLabel: mergedStrings.cancel, accessibilityRole: "button" },
|
|
249
264
|
react_1.default.createElement(react_native_1.Text, { style: styles.closeButtonLabel }, "\u00D7"))),
|
package/package.json
CHANGED
package/src/FullDocScanner.tsx
CHANGED
|
@@ -12,7 +12,12 @@ import { launchImageLibrary } from 'react-native-image-picker';
|
|
|
12
12
|
import ImageCropPicker from 'react-native-image-crop-picker';
|
|
13
13
|
import { DocScanner } from './DocScanner';
|
|
14
14
|
import type { CapturedDocument } from './types';
|
|
15
|
-
import type {
|
|
15
|
+
import type {
|
|
16
|
+
DetectionConfig,
|
|
17
|
+
DocScannerHandle,
|
|
18
|
+
DocScannerCapture,
|
|
19
|
+
RectangleDetectEvent,
|
|
20
|
+
} from './DocScanner';
|
|
16
21
|
|
|
17
22
|
const stripFileUri = (value: string) => value.replace(/^file:\/\//, '');
|
|
18
23
|
|
|
@@ -55,7 +60,6 @@ export interface FullDocScannerProps {
|
|
|
55
60
|
gridLineWidth?: number;
|
|
56
61
|
showGrid?: boolean;
|
|
57
62
|
strings?: FullDocScannerStrings;
|
|
58
|
-
manualCapture?: boolean;
|
|
59
63
|
minStableFrames?: number;
|
|
60
64
|
onError?: (error: Error) => void;
|
|
61
65
|
enableGallery?: boolean;
|
|
@@ -72,7 +76,6 @@ export const FullDocScanner: React.FC<FullDocScannerProps> = ({
|
|
|
72
76
|
gridLineWidth,
|
|
73
77
|
showGrid,
|
|
74
78
|
strings,
|
|
75
|
-
manualCapture = false,
|
|
76
79
|
minStableFrames,
|
|
77
80
|
onError,
|
|
78
81
|
enableGallery = true,
|
|
@@ -166,11 +169,16 @@ export const FullDocScanner: React.FC<FullDocScannerProps> = ({
|
|
|
166
169
|
captureMode: captureModeRef.current,
|
|
167
170
|
});
|
|
168
171
|
|
|
172
|
+
if (document.origin === 'auto') {
|
|
173
|
+
console.log('[FullDocScanner] Ignoring auto capture result');
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
|
|
169
177
|
const captureMode = captureModeRef.current;
|
|
170
178
|
|
|
171
|
-
// Ignore auto captures - only process manual captures
|
|
172
179
|
if (!captureMode) {
|
|
173
|
-
console.
|
|
180
|
+
console.warn('[FullDocScanner] Missing capture mode for manual capture result');
|
|
181
|
+
captureModeRef.current = null;
|
|
174
182
|
return;
|
|
175
183
|
}
|
|
176
184
|
|
|
@@ -302,10 +310,23 @@ export const FullDocScanner: React.FC<FullDocScannerProps> = ({
|
|
|
302
310
|
}
|
|
303
311
|
}, []);
|
|
304
312
|
|
|
305
|
-
const handleRectangleDetect = useCallback((event:
|
|
306
|
-
|
|
307
|
-
const
|
|
308
|
-
|
|
313
|
+
const handleRectangleDetect = useCallback((event: RectangleDetectEvent) => {
|
|
314
|
+
const stableCounter = event.stableCounter ?? 0;
|
|
315
|
+
const hasRectangle = Boolean(event.rectangleOnScreen ?? event.rectangleCoordinates);
|
|
316
|
+
const isGoodRectangle = event.lastDetectionType === 0 && hasRectangle && stableCounter > 0;
|
|
317
|
+
|
|
318
|
+
setRectangleDetected((prev) => {
|
|
319
|
+
if (prev !== isGoodRectangle) {
|
|
320
|
+
console.log('[FullDocScanner] Rectangle detection update', {
|
|
321
|
+
lastDetectionType: event.lastDetectionType,
|
|
322
|
+
stableCounter,
|
|
323
|
+
hasRectangle,
|
|
324
|
+
isGoodRectangle,
|
|
325
|
+
});
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
return isGoodRectangle;
|
|
329
|
+
});
|
|
309
330
|
}, []);
|
|
310
331
|
|
|
311
332
|
return (
|
|
@@ -341,7 +362,7 @@ export const FullDocScanner: React.FC<FullDocScannerProps> = ({
|
|
|
341
362
|
<View style={styles.flex}>
|
|
342
363
|
<DocScanner
|
|
343
364
|
ref={docScannerRef}
|
|
344
|
-
autoCapture={
|
|
365
|
+
autoCapture={true}
|
|
345
366
|
overlayColor={overlayColor}
|
|
346
367
|
showGrid={showGrid}
|
|
347
368
|
gridColor={resolvedGridColor}
|