react-native-rectangle-doc-scanner 3.52.0 → 3.54.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.js +35 -11
- package/package.json +1 -1
- package/src/FullDocScanner.tsx +46 -13
package/dist/FullDocScanner.js
CHANGED
|
@@ -61,6 +61,7 @@ const FullDocScanner = ({ onResult, onClose, detectionConfig, overlayColor = '#3
|
|
|
61
61
|
const resolvedGridColor = gridColor ?? overlayColor;
|
|
62
62
|
const docScannerRef = (0, react_1.useRef)(null);
|
|
63
63
|
const captureModeRef = (0, react_1.useRef)(null);
|
|
64
|
+
const captureInProgressRef = (0, react_1.useRef)(false);
|
|
64
65
|
const mergedStrings = (0, react_1.useMemo)(() => ({
|
|
65
66
|
captureHint: strings?.captureHint,
|
|
66
67
|
manualHint: strings?.manualHint,
|
|
@@ -122,10 +123,15 @@ const FullDocScanner = ({ onResult, onClose, detectionConfig, overlayColor = '#3
|
|
|
122
123
|
initialPath: document.initialPath,
|
|
123
124
|
captureMode: captureModeRef.current,
|
|
124
125
|
});
|
|
126
|
+
captureInProgressRef.current = false;
|
|
127
|
+
if (document.origin === 'auto') {
|
|
128
|
+
console.log('[FullDocScanner] Ignoring auto capture result');
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
125
131
|
const captureMode = captureModeRef.current;
|
|
126
|
-
// Ignore auto captures - only process manual captures
|
|
127
132
|
if (!captureMode) {
|
|
128
|
-
console.
|
|
133
|
+
console.warn('[FullDocScanner] Missing capture mode for manual capture result');
|
|
134
|
+
captureModeRef.current = null;
|
|
129
135
|
return;
|
|
130
136
|
}
|
|
131
137
|
captureModeRef.current = null;
|
|
@@ -146,33 +152,39 @@ const FullDocScanner = ({ onResult, onClose, detectionConfig, overlayColor = '#3
|
|
|
146
152
|
await openCropper(normalizedDoc.path);
|
|
147
153
|
}, [openCropper]);
|
|
148
154
|
const triggerManualCapture = (0, react_1.useCallback)(() => {
|
|
155
|
+
const scannerInstance = docScannerRef.current;
|
|
156
|
+
const hasScanner = !!scannerInstance;
|
|
149
157
|
console.log('[FullDocScanner] triggerManualCapture called', {
|
|
150
158
|
processing,
|
|
151
|
-
hasRef:
|
|
159
|
+
hasRef: hasScanner,
|
|
152
160
|
rectangleDetected,
|
|
153
161
|
currentCaptureMode: captureModeRef.current,
|
|
162
|
+
captureInProgress: captureInProgressRef.current,
|
|
154
163
|
});
|
|
155
164
|
if (processing) {
|
|
156
165
|
console.log('[FullDocScanner] Already processing, skipping manual capture');
|
|
157
166
|
return;
|
|
158
167
|
}
|
|
159
|
-
|
|
160
|
-
if (captureModeRef.current !== null) {
|
|
168
|
+
if (captureInProgressRef.current) {
|
|
161
169
|
console.log('[FullDocScanner] Capture already in progress, skipping');
|
|
162
170
|
return;
|
|
163
171
|
}
|
|
164
|
-
if (!
|
|
172
|
+
if (!hasScanner) {
|
|
165
173
|
console.error('[FullDocScanner] DocScanner ref not available');
|
|
166
174
|
return;
|
|
167
175
|
}
|
|
168
176
|
console.log('[FullDocScanner] Starting manual capture, grid detected:', rectangleDetected);
|
|
169
|
-
|
|
170
|
-
|
|
177
|
+
const captureMode = rectangleDetected ? 'grid' : 'no-grid';
|
|
178
|
+
captureModeRef.current = captureMode;
|
|
179
|
+
captureInProgressRef.current = true;
|
|
180
|
+
scannerInstance.capture()
|
|
171
181
|
.then((result) => {
|
|
172
182
|
console.log('[FullDocScanner] Manual capture success:', result);
|
|
183
|
+
captureInProgressRef.current = false;
|
|
173
184
|
})
|
|
174
185
|
.catch((error) => {
|
|
175
186
|
captureModeRef.current = null;
|
|
187
|
+
captureInProgressRef.current = false;
|
|
176
188
|
console.error('[FullDocScanner] Manual capture failed:', error);
|
|
177
189
|
if (error instanceof Error && error.message !== 'capture_in_progress') {
|
|
178
190
|
emitError(error, 'Failed to capture image.');
|
|
@@ -223,15 +235,27 @@ const FullDocScanner = ({ onResult, onClose, detectionConfig, overlayColor = '#3
|
|
|
223
235
|
setProcessing(false);
|
|
224
236
|
setRectangleDetected(false);
|
|
225
237
|
captureModeRef.current = null;
|
|
238
|
+
captureInProgressRef.current = false;
|
|
226
239
|
// Reset DocScanner state
|
|
227
240
|
if (docScannerRef.current?.reset) {
|
|
228
241
|
docScannerRef.current.reset();
|
|
229
242
|
}
|
|
230
243
|
}, []);
|
|
231
244
|
const handleRectangleDetect = (0, react_1.useCallback)((event) => {
|
|
232
|
-
|
|
233
|
-
const
|
|
234
|
-
|
|
245
|
+
const stableCounter = event.stableCounter ?? 0;
|
|
246
|
+
const hasRectangle = Boolean(event.rectangleOnScreen ?? event.rectangleCoordinates);
|
|
247
|
+
const isGoodRectangle = hasRectangle;
|
|
248
|
+
setRectangleDetected((prev) => {
|
|
249
|
+
if (prev !== isGoodRectangle) {
|
|
250
|
+
console.log('[FullDocScanner] Rectangle detection update', {
|
|
251
|
+
lastDetectionType: event.lastDetectionType,
|
|
252
|
+
stableCounter,
|
|
253
|
+
hasRectangle,
|
|
254
|
+
isGoodRectangle,
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
return isGoodRectangle;
|
|
258
|
+
});
|
|
235
259
|
}, []);
|
|
236
260
|
return (react_1.default.createElement(react_native_1.View, { style: styles.container },
|
|
237
261
|
croppedImageData ? (
|
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
|
|
|
@@ -84,6 +89,7 @@ export const FullDocScanner: React.FC<FullDocScannerProps> = ({
|
|
|
84
89
|
const resolvedGridColor = gridColor ?? overlayColor;
|
|
85
90
|
const docScannerRef = useRef<DocScannerHandle | null>(null);
|
|
86
91
|
const captureModeRef = useRef<'grid' | 'no-grid' | null>(null);
|
|
92
|
+
const captureInProgressRef = useRef(false);
|
|
87
93
|
|
|
88
94
|
const mergedStrings = useMemo(
|
|
89
95
|
() => ({
|
|
@@ -164,11 +170,18 @@ export const FullDocScanner: React.FC<FullDocScannerProps> = ({
|
|
|
164
170
|
captureMode: captureModeRef.current,
|
|
165
171
|
});
|
|
166
172
|
|
|
173
|
+
captureInProgressRef.current = false;
|
|
174
|
+
|
|
175
|
+
if (document.origin === 'auto') {
|
|
176
|
+
console.log('[FullDocScanner] Ignoring auto capture result');
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
|
|
167
180
|
const captureMode = captureModeRef.current;
|
|
168
181
|
|
|
169
|
-
// Ignore auto captures - only process manual captures
|
|
170
182
|
if (!captureMode) {
|
|
171
|
-
console.
|
|
183
|
+
console.warn('[FullDocScanner] Missing capture mode for manual capture result');
|
|
184
|
+
captureModeRef.current = null;
|
|
172
185
|
return;
|
|
173
186
|
}
|
|
174
187
|
|
|
@@ -197,11 +210,14 @@ export const FullDocScanner: React.FC<FullDocScannerProps> = ({
|
|
|
197
210
|
);
|
|
198
211
|
|
|
199
212
|
const triggerManualCapture = useCallback(() => {
|
|
213
|
+
const scannerInstance = docScannerRef.current;
|
|
214
|
+
const hasScanner = !!scannerInstance;
|
|
200
215
|
console.log('[FullDocScanner] triggerManualCapture called', {
|
|
201
216
|
processing,
|
|
202
|
-
hasRef:
|
|
217
|
+
hasRef: hasScanner,
|
|
203
218
|
rectangleDetected,
|
|
204
219
|
currentCaptureMode: captureModeRef.current,
|
|
220
|
+
captureInProgress: captureInProgressRef.current,
|
|
205
221
|
});
|
|
206
222
|
|
|
207
223
|
if (processing) {
|
|
@@ -209,27 +225,30 @@ export const FullDocScanner: React.FC<FullDocScannerProps> = ({
|
|
|
209
225
|
return;
|
|
210
226
|
}
|
|
211
227
|
|
|
212
|
-
|
|
213
|
-
if (captureModeRef.current !== null) {
|
|
228
|
+
if (captureInProgressRef.current) {
|
|
214
229
|
console.log('[FullDocScanner] Capture already in progress, skipping');
|
|
215
230
|
return;
|
|
216
231
|
}
|
|
217
232
|
|
|
218
|
-
if (!
|
|
233
|
+
if (!hasScanner) {
|
|
219
234
|
console.error('[FullDocScanner] DocScanner ref not available');
|
|
220
235
|
return;
|
|
221
236
|
}
|
|
222
237
|
|
|
223
238
|
console.log('[FullDocScanner] Starting manual capture, grid detected:', rectangleDetected);
|
|
224
239
|
|
|
225
|
-
|
|
240
|
+
const captureMode = rectangleDetected ? 'grid' : 'no-grid';
|
|
241
|
+
captureModeRef.current = captureMode;
|
|
242
|
+
captureInProgressRef.current = true;
|
|
226
243
|
|
|
227
|
-
|
|
244
|
+
scannerInstance.capture()
|
|
228
245
|
.then((result) => {
|
|
229
246
|
console.log('[FullDocScanner] Manual capture success:', result);
|
|
247
|
+
captureInProgressRef.current = false;
|
|
230
248
|
})
|
|
231
249
|
.catch((error: unknown) => {
|
|
232
250
|
captureModeRef.current = null;
|
|
251
|
+
captureInProgressRef.current = false;
|
|
233
252
|
console.error('[FullDocScanner] Manual capture failed:', error);
|
|
234
253
|
if (error instanceof Error && error.message !== 'capture_in_progress') {
|
|
235
254
|
emitError(
|
|
@@ -294,16 +313,30 @@ export const FullDocScanner: React.FC<FullDocScannerProps> = ({
|
|
|
294
313
|
setProcessing(false);
|
|
295
314
|
setRectangleDetected(false);
|
|
296
315
|
captureModeRef.current = null;
|
|
316
|
+
captureInProgressRef.current = false;
|
|
297
317
|
// Reset DocScanner state
|
|
298
318
|
if (docScannerRef.current?.reset) {
|
|
299
319
|
docScannerRef.current.reset();
|
|
300
320
|
}
|
|
301
321
|
}, []);
|
|
302
322
|
|
|
303
|
-
const handleRectangleDetect = useCallback((event:
|
|
304
|
-
|
|
305
|
-
const
|
|
306
|
-
|
|
323
|
+
const handleRectangleDetect = useCallback((event: RectangleDetectEvent) => {
|
|
324
|
+
const stableCounter = event.stableCounter ?? 0;
|
|
325
|
+
const hasRectangle = Boolean(event.rectangleOnScreen ?? event.rectangleCoordinates);
|
|
326
|
+
const isGoodRectangle = hasRectangle;
|
|
327
|
+
|
|
328
|
+
setRectangleDetected((prev) => {
|
|
329
|
+
if (prev !== isGoodRectangle) {
|
|
330
|
+
console.log('[FullDocScanner] Rectangle detection update', {
|
|
331
|
+
lastDetectionType: event.lastDetectionType,
|
|
332
|
+
stableCounter,
|
|
333
|
+
hasRectangle,
|
|
334
|
+
isGoodRectangle,
|
|
335
|
+
});
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
return isGoodRectangle;
|
|
339
|
+
});
|
|
307
340
|
}, []);
|
|
308
341
|
|
|
309
342
|
return (
|