react-native-rectangle-doc-scanner 3.49.0 → 3.51.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 +29 -8
- package/package.json +1 -1
- package/src/FullDocScanner.tsx +36 -7
package/dist/FullDocScanner.js
CHANGED
|
@@ -60,6 +60,7 @@ const FullDocScanner = ({ onResult, onClose, detectionConfig, overlayColor = '#3
|
|
|
60
60
|
const [rectangleDetected, setRectangleDetected] = (0, react_1.useState)(false);
|
|
61
61
|
const resolvedGridColor = gridColor ?? overlayColor;
|
|
62
62
|
const docScannerRef = (0, react_1.useRef)(null);
|
|
63
|
+
const captureModeRef = (0, react_1.useRef)(null);
|
|
63
64
|
const mergedStrings = (0, react_1.useMemo)(() => ({
|
|
64
65
|
captureHint: strings?.captureHint,
|
|
65
66
|
manualHint: strings?.manualHint,
|
|
@@ -119,46 +120,65 @@ const FullDocScanner = ({ onResult, onClose, detectionConfig, overlayColor = '#3
|
|
|
119
120
|
path: document.path,
|
|
120
121
|
croppedPath: document.croppedPath,
|
|
121
122
|
initialPath: document.initialPath,
|
|
123
|
+
captureMode: captureModeRef.current,
|
|
122
124
|
});
|
|
125
|
+
const captureMode = captureModeRef.current;
|
|
126
|
+
// Ignore auto captures - only process manual captures
|
|
127
|
+
if (!captureMode) {
|
|
128
|
+
console.log('[FullDocScanner] Ignoring auto capture - only manual captures allowed');
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
captureModeRef.current = null;
|
|
123
132
|
const normalizedDoc = normalizeCapturedDocument(document);
|
|
124
|
-
|
|
133
|
+
if (captureMode === 'no-grid') {
|
|
134
|
+
console.log('[FullDocScanner] No grid at capture button press: opening cropper for manual selection');
|
|
135
|
+
await openCropper(normalizedDoc.path);
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
125
138
|
if (normalizedDoc.croppedPath) {
|
|
126
139
|
console.log('[FullDocScanner] Grid detected: using pre-cropped image', normalizedDoc.croppedPath);
|
|
127
140
|
setCroppedImageData({
|
|
128
141
|
path: normalizedDoc.croppedPath,
|
|
129
142
|
});
|
|
143
|
+
return;
|
|
130
144
|
}
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
console.log('[FullDocScanner] No grid detected: opening cropper for manual crop', normalizedDoc.path);
|
|
134
|
-
await openCropper(normalizedDoc.path);
|
|
135
|
-
}
|
|
145
|
+
console.log('[FullDocScanner] Fallback to manual crop (no croppedPath available)');
|
|
146
|
+
await openCropper(normalizedDoc.path);
|
|
136
147
|
}, [openCropper]);
|
|
137
148
|
const triggerManualCapture = (0, react_1.useCallback)(() => {
|
|
138
149
|
console.log('[FullDocScanner] triggerManualCapture called', {
|
|
139
150
|
processing,
|
|
140
151
|
hasRef: !!docScannerRef.current,
|
|
152
|
+
rectangleDetected,
|
|
153
|
+
currentCaptureMode: captureModeRef.current,
|
|
141
154
|
});
|
|
142
155
|
if (processing) {
|
|
143
156
|
console.log('[FullDocScanner] Already processing, skipping manual capture');
|
|
144
157
|
return;
|
|
145
158
|
}
|
|
159
|
+
// Check if capture is already in progress
|
|
160
|
+
if (captureModeRef.current !== null) {
|
|
161
|
+
console.log('[FullDocScanner] Capture already in progress, skipping');
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
146
164
|
if (!docScannerRef.current) {
|
|
147
165
|
console.error('[FullDocScanner] DocScanner ref not available');
|
|
148
166
|
return;
|
|
149
167
|
}
|
|
150
|
-
console.log('[FullDocScanner] Starting manual capture');
|
|
168
|
+
console.log('[FullDocScanner] Starting manual capture, grid detected:', rectangleDetected);
|
|
169
|
+
captureModeRef.current = rectangleDetected ? 'grid' : 'no-grid';
|
|
151
170
|
docScannerRef.current.capture()
|
|
152
171
|
.then((result) => {
|
|
153
172
|
console.log('[FullDocScanner] Manual capture success:', result);
|
|
154
173
|
})
|
|
155
174
|
.catch((error) => {
|
|
175
|
+
captureModeRef.current = null;
|
|
156
176
|
console.error('[FullDocScanner] Manual capture failed:', error);
|
|
157
177
|
if (error instanceof Error && error.message !== 'capture_in_progress') {
|
|
158
178
|
emitError(error, 'Failed to capture image.');
|
|
159
179
|
}
|
|
160
180
|
});
|
|
161
|
-
}, [processing, emitError]);
|
|
181
|
+
}, [processing, rectangleDetected, emitError]);
|
|
162
182
|
const handleGalleryPick = (0, react_1.useCallback)(async () => {
|
|
163
183
|
console.log('[FullDocScanner] handleGalleryPick called');
|
|
164
184
|
if (processing || isGalleryOpen) {
|
|
@@ -202,6 +222,7 @@ const FullDocScanner = ({ onResult, onClose, detectionConfig, overlayColor = '#3
|
|
|
202
222
|
setCroppedImageData(null);
|
|
203
223
|
setProcessing(false);
|
|
204
224
|
setRectangleDetected(false);
|
|
225
|
+
captureModeRef.current = null;
|
|
205
226
|
// Reset DocScanner state
|
|
206
227
|
if (docScannerRef.current?.reset) {
|
|
207
228
|
docScannerRef.current.reset();
|
package/package.json
CHANGED
package/src/FullDocScanner.tsx
CHANGED
|
@@ -85,6 +85,7 @@ export const FullDocScanner: React.FC<FullDocScannerProps> = ({
|
|
|
85
85
|
const [rectangleDetected, setRectangleDetected] = useState(false);
|
|
86
86
|
const resolvedGridColor = gridColor ?? overlayColor;
|
|
87
87
|
const docScannerRef = useRef<DocScannerHandle | null>(null);
|
|
88
|
+
const captureModeRef = useRef<'grid' | 'no-grid' | null>(null);
|
|
88
89
|
|
|
89
90
|
const mergedStrings = useMemo(
|
|
90
91
|
() => ({
|
|
@@ -162,21 +163,37 @@ export const FullDocScanner: React.FC<FullDocScannerProps> = ({
|
|
|
162
163
|
path: document.path,
|
|
163
164
|
croppedPath: document.croppedPath,
|
|
164
165
|
initialPath: document.initialPath,
|
|
166
|
+
captureMode: captureModeRef.current,
|
|
165
167
|
});
|
|
166
168
|
|
|
169
|
+
const captureMode = captureModeRef.current;
|
|
170
|
+
|
|
171
|
+
// Ignore auto captures - only process manual captures
|
|
172
|
+
if (!captureMode) {
|
|
173
|
+
console.log('[FullDocScanner] Ignoring auto capture - only manual captures allowed');
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
captureModeRef.current = null;
|
|
178
|
+
|
|
167
179
|
const normalizedDoc = normalizeCapturedDocument(document);
|
|
168
180
|
|
|
169
|
-
|
|
181
|
+
if (captureMode === 'no-grid') {
|
|
182
|
+
console.log('[FullDocScanner] No grid at capture button press: opening cropper for manual selection');
|
|
183
|
+
await openCropper(normalizedDoc.path);
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
|
|
170
187
|
if (normalizedDoc.croppedPath) {
|
|
171
188
|
console.log('[FullDocScanner] Grid detected: using pre-cropped image', normalizedDoc.croppedPath);
|
|
172
189
|
setCroppedImageData({
|
|
173
190
|
path: normalizedDoc.croppedPath,
|
|
174
191
|
});
|
|
175
|
-
|
|
176
|
-
// No grid: open cropper for manual crop
|
|
177
|
-
console.log('[FullDocScanner] No grid detected: opening cropper for manual crop', normalizedDoc.path);
|
|
178
|
-
await openCropper(normalizedDoc.path);
|
|
192
|
+
return;
|
|
179
193
|
}
|
|
194
|
+
|
|
195
|
+
console.log('[FullDocScanner] Fallback to manual crop (no croppedPath available)');
|
|
196
|
+
await openCropper(normalizedDoc.path);
|
|
180
197
|
},
|
|
181
198
|
[openCropper],
|
|
182
199
|
);
|
|
@@ -185,6 +202,8 @@ export const FullDocScanner: React.FC<FullDocScannerProps> = ({
|
|
|
185
202
|
console.log('[FullDocScanner] triggerManualCapture called', {
|
|
186
203
|
processing,
|
|
187
204
|
hasRef: !!docScannerRef.current,
|
|
205
|
+
rectangleDetected,
|
|
206
|
+
currentCaptureMode: captureModeRef.current,
|
|
188
207
|
});
|
|
189
208
|
|
|
190
209
|
if (processing) {
|
|
@@ -192,18 +211,27 @@ export const FullDocScanner: React.FC<FullDocScannerProps> = ({
|
|
|
192
211
|
return;
|
|
193
212
|
}
|
|
194
213
|
|
|
214
|
+
// Check if capture is already in progress
|
|
215
|
+
if (captureModeRef.current !== null) {
|
|
216
|
+
console.log('[FullDocScanner] Capture already in progress, skipping');
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
219
|
+
|
|
195
220
|
if (!docScannerRef.current) {
|
|
196
221
|
console.error('[FullDocScanner] DocScanner ref not available');
|
|
197
222
|
return;
|
|
198
223
|
}
|
|
199
224
|
|
|
200
|
-
console.log('[FullDocScanner] Starting manual capture');
|
|
225
|
+
console.log('[FullDocScanner] Starting manual capture, grid detected:', rectangleDetected);
|
|
226
|
+
|
|
227
|
+
captureModeRef.current = rectangleDetected ? 'grid' : 'no-grid';
|
|
201
228
|
|
|
202
229
|
docScannerRef.current.capture()
|
|
203
230
|
.then((result) => {
|
|
204
231
|
console.log('[FullDocScanner] Manual capture success:', result);
|
|
205
232
|
})
|
|
206
233
|
.catch((error: unknown) => {
|
|
234
|
+
captureModeRef.current = null;
|
|
207
235
|
console.error('[FullDocScanner] Manual capture failed:', error);
|
|
208
236
|
if (error instanceof Error && error.message !== 'capture_in_progress') {
|
|
209
237
|
emitError(
|
|
@@ -212,7 +240,7 @@ export const FullDocScanner: React.FC<FullDocScannerProps> = ({
|
|
|
212
240
|
);
|
|
213
241
|
}
|
|
214
242
|
});
|
|
215
|
-
}, [processing, emitError]);
|
|
243
|
+
}, [processing, rectangleDetected, emitError]);
|
|
216
244
|
|
|
217
245
|
const handleGalleryPick = useCallback(async () => {
|
|
218
246
|
console.log('[FullDocScanner] handleGalleryPick called');
|
|
@@ -267,6 +295,7 @@ export const FullDocScanner: React.FC<FullDocScannerProps> = ({
|
|
|
267
295
|
setCroppedImageData(null);
|
|
268
296
|
setProcessing(false);
|
|
269
297
|
setRectangleDetected(false);
|
|
298
|
+
captureModeRef.current = null;
|
|
270
299
|
// Reset DocScanner state
|
|
271
300
|
if (docScannerRef.current?.reset) {
|
|
272
301
|
docScannerRef.current.reset();
|