react-native-rectangle-doc-scanner 3.49.0 → 3.50.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 +16 -7
- package/package.json +1 -1
- package/src/FullDocScanner.tsx +20 -6
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,
|
|
@@ -120,24 +121,29 @@ const FullDocScanner = ({ onResult, onClose, detectionConfig, overlayColor = '#3
|
|
|
120
121
|
croppedPath: document.croppedPath,
|
|
121
122
|
initialPath: document.initialPath,
|
|
122
123
|
});
|
|
124
|
+
const captureMode = captureModeRef.current;
|
|
125
|
+
captureModeRef.current = null;
|
|
123
126
|
const normalizedDoc = normalizeCapturedDocument(document);
|
|
124
|
-
|
|
127
|
+
if (captureMode === 'no-grid') {
|
|
128
|
+
console.log('[FullDocScanner] No grid at capture button press: opening cropper for manual selection');
|
|
129
|
+
await openCropper(normalizedDoc.path);
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
125
132
|
if (normalizedDoc.croppedPath) {
|
|
126
133
|
console.log('[FullDocScanner] Grid detected: using pre-cropped image', normalizedDoc.croppedPath);
|
|
127
134
|
setCroppedImageData({
|
|
128
135
|
path: normalizedDoc.croppedPath,
|
|
129
136
|
});
|
|
137
|
+
return;
|
|
130
138
|
}
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
console.log('[FullDocScanner] No grid detected: opening cropper for manual crop', normalizedDoc.path);
|
|
134
|
-
await openCropper(normalizedDoc.path);
|
|
135
|
-
}
|
|
139
|
+
console.log('[FullDocScanner] Fallback to manual crop (no croppedPath available)');
|
|
140
|
+
await openCropper(normalizedDoc.path);
|
|
136
141
|
}, [openCropper]);
|
|
137
142
|
const triggerManualCapture = (0, react_1.useCallback)(() => {
|
|
138
143
|
console.log('[FullDocScanner] triggerManualCapture called', {
|
|
139
144
|
processing,
|
|
140
145
|
hasRef: !!docScannerRef.current,
|
|
146
|
+
rectangleDetected,
|
|
141
147
|
});
|
|
142
148
|
if (processing) {
|
|
143
149
|
console.log('[FullDocScanner] Already processing, skipping manual capture');
|
|
@@ -148,17 +154,19 @@ const FullDocScanner = ({ onResult, onClose, detectionConfig, overlayColor = '#3
|
|
|
148
154
|
return;
|
|
149
155
|
}
|
|
150
156
|
console.log('[FullDocScanner] Starting manual capture');
|
|
157
|
+
captureModeRef.current = rectangleDetected ? 'grid' : 'no-grid';
|
|
151
158
|
docScannerRef.current.capture()
|
|
152
159
|
.then((result) => {
|
|
153
160
|
console.log('[FullDocScanner] Manual capture success:', result);
|
|
154
161
|
})
|
|
155
162
|
.catch((error) => {
|
|
163
|
+
captureModeRef.current = null;
|
|
156
164
|
console.error('[FullDocScanner] Manual capture failed:', error);
|
|
157
165
|
if (error instanceof Error && error.message !== 'capture_in_progress') {
|
|
158
166
|
emitError(error, 'Failed to capture image.');
|
|
159
167
|
}
|
|
160
168
|
});
|
|
161
|
-
}, [processing, emitError]);
|
|
169
|
+
}, [processing, rectangleDetected, emitError]);
|
|
162
170
|
const handleGalleryPick = (0, react_1.useCallback)(async () => {
|
|
163
171
|
console.log('[FullDocScanner] handleGalleryPick called');
|
|
164
172
|
if (processing || isGalleryOpen) {
|
|
@@ -202,6 +210,7 @@ const FullDocScanner = ({ onResult, onClose, detectionConfig, overlayColor = '#3
|
|
|
202
210
|
setCroppedImageData(null);
|
|
203
211
|
setProcessing(false);
|
|
204
212
|
setRectangleDetected(false);
|
|
213
|
+
captureModeRef.current = null;
|
|
205
214
|
// Reset DocScanner state
|
|
206
215
|
if (docScannerRef.current?.reset) {
|
|
207
216
|
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
|
() => ({
|
|
@@ -164,19 +165,27 @@ export const FullDocScanner: React.FC<FullDocScannerProps> = ({
|
|
|
164
165
|
initialPath: document.initialPath,
|
|
165
166
|
});
|
|
166
167
|
|
|
168
|
+
const captureMode = captureModeRef.current;
|
|
169
|
+
captureModeRef.current = null;
|
|
170
|
+
|
|
167
171
|
const normalizedDoc = normalizeCapturedDocument(document);
|
|
168
172
|
|
|
169
|
-
|
|
173
|
+
if (captureMode === 'no-grid') {
|
|
174
|
+
console.log('[FullDocScanner] No grid at capture button press: opening cropper for manual selection');
|
|
175
|
+
await openCropper(normalizedDoc.path);
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
|
|
170
179
|
if (normalizedDoc.croppedPath) {
|
|
171
180
|
console.log('[FullDocScanner] Grid detected: using pre-cropped image', normalizedDoc.croppedPath);
|
|
172
181
|
setCroppedImageData({
|
|
173
182
|
path: normalizedDoc.croppedPath,
|
|
174
183
|
});
|
|
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);
|
|
184
|
+
return;
|
|
179
185
|
}
|
|
186
|
+
|
|
187
|
+
console.log('[FullDocScanner] Fallback to manual crop (no croppedPath available)');
|
|
188
|
+
await openCropper(normalizedDoc.path);
|
|
180
189
|
},
|
|
181
190
|
[openCropper],
|
|
182
191
|
);
|
|
@@ -185,6 +194,7 @@ export const FullDocScanner: React.FC<FullDocScannerProps> = ({
|
|
|
185
194
|
console.log('[FullDocScanner] triggerManualCapture called', {
|
|
186
195
|
processing,
|
|
187
196
|
hasRef: !!docScannerRef.current,
|
|
197
|
+
rectangleDetected,
|
|
188
198
|
});
|
|
189
199
|
|
|
190
200
|
if (processing) {
|
|
@@ -199,11 +209,14 @@ export const FullDocScanner: React.FC<FullDocScannerProps> = ({
|
|
|
199
209
|
|
|
200
210
|
console.log('[FullDocScanner] Starting manual capture');
|
|
201
211
|
|
|
212
|
+
captureModeRef.current = rectangleDetected ? 'grid' : 'no-grid';
|
|
213
|
+
|
|
202
214
|
docScannerRef.current.capture()
|
|
203
215
|
.then((result) => {
|
|
204
216
|
console.log('[FullDocScanner] Manual capture success:', result);
|
|
205
217
|
})
|
|
206
218
|
.catch((error: unknown) => {
|
|
219
|
+
captureModeRef.current = null;
|
|
207
220
|
console.error('[FullDocScanner] Manual capture failed:', error);
|
|
208
221
|
if (error instanceof Error && error.message !== 'capture_in_progress') {
|
|
209
222
|
emitError(
|
|
@@ -212,7 +225,7 @@ export const FullDocScanner: React.FC<FullDocScannerProps> = ({
|
|
|
212
225
|
);
|
|
213
226
|
}
|
|
214
227
|
});
|
|
215
|
-
}, [processing, emitError]);
|
|
228
|
+
}, [processing, rectangleDetected, emitError]);
|
|
216
229
|
|
|
217
230
|
const handleGalleryPick = useCallback(async () => {
|
|
218
231
|
console.log('[FullDocScanner] handleGalleryPick called');
|
|
@@ -267,6 +280,7 @@ export const FullDocScanner: React.FC<FullDocScannerProps> = ({
|
|
|
267
280
|
setCroppedImageData(null);
|
|
268
281
|
setProcessing(false);
|
|
269
282
|
setRectangleDetected(false);
|
|
283
|
+
captureModeRef.current = null;
|
|
270
284
|
// Reset DocScanner state
|
|
271
285
|
if (docScannerRef.current?.reset) {
|
|
272
286
|
docScannerRef.current.reset();
|