react-native-rectangle-doc-scanner 3.34.0 → 3.36.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 +37 -15
- package/package.json +1 -1
- package/src/FullDocScanner.tsx +39 -17
package/dist/FullDocScanner.js
CHANGED
|
@@ -120,13 +120,16 @@ const FullDocScanner = ({ onResult, onClose, detectionConfig, overlayColor = '#3
|
|
|
120
120
|
}
|
|
121
121
|
}, [onError]);
|
|
122
122
|
const processAutoCapture = (0, react_1.useCallback)(async (document) => {
|
|
123
|
+
console.log('[FullDocScanner] processAutoCapture started');
|
|
123
124
|
manualCapturePending.current = false;
|
|
124
125
|
const normalizedDoc = normalizeCapturedDocument(document);
|
|
125
126
|
const cropManager = react_native_1.NativeModules.CustomCropManager;
|
|
126
127
|
if (!cropManager?.crop) {
|
|
128
|
+
console.error('[FullDocScanner] CustomCropManager.crop is not available');
|
|
127
129
|
emitError(new Error('CustomCropManager.crop is not available'));
|
|
128
130
|
return;
|
|
129
131
|
}
|
|
132
|
+
console.log('[FullDocScanner] Setting processing to true');
|
|
130
133
|
setProcessing(true);
|
|
131
134
|
try {
|
|
132
135
|
const size = await resolveImageSize(normalizedDoc.path, normalizedDoc.width, normalizedDoc.height);
|
|
@@ -144,6 +147,11 @@ const FullDocScanner = ({ onResult, onClose, detectionConfig, overlayColor = '#3
|
|
|
144
147
|
? (0, coordinate_1.scaleRectangle)(rectangleBase, baseWidth || targetWidth, baseHeight || targetHeight, targetWidth, targetHeight)
|
|
145
148
|
: null;
|
|
146
149
|
const rectangleToUse = scaledRectangle ?? (0, coordinate_1.createFullImageRectangle)(targetWidth, targetHeight);
|
|
150
|
+
console.log('[FullDocScanner] Calling CustomCropManager.crop with:', {
|
|
151
|
+
rectangle: rectangleToUse,
|
|
152
|
+
imageUri: ensureFileUri(normalizedDoc.path),
|
|
153
|
+
targetSize: { width: targetWidth, height: targetHeight },
|
|
154
|
+
});
|
|
147
155
|
const base64 = await new Promise((resolve, reject) => {
|
|
148
156
|
cropManager.crop({
|
|
149
157
|
topLeft: rectangleToUse.topLeft,
|
|
@@ -154,9 +162,11 @@ const FullDocScanner = ({ onResult, onClose, detectionConfig, overlayColor = '#3
|
|
|
154
162
|
height: targetHeight,
|
|
155
163
|
}, ensureFileUri(normalizedDoc.path), (error, result) => {
|
|
156
164
|
if (error) {
|
|
165
|
+
console.error('[FullDocScanner] CustomCropManager.crop error:', error);
|
|
157
166
|
reject(error instanceof Error ? error : new Error('Crop failed'));
|
|
158
167
|
return;
|
|
159
168
|
}
|
|
169
|
+
console.log('[FullDocScanner] CustomCropManager.crop success, base64 length:', result.image?.length);
|
|
160
170
|
resolve(result.image);
|
|
161
171
|
});
|
|
162
172
|
});
|
|
@@ -164,11 +174,13 @@ const FullDocScanner = ({ onResult, onClose, detectionConfig, overlayColor = '#3
|
|
|
164
174
|
...normalizedDoc,
|
|
165
175
|
rectangle: rectangleToUse,
|
|
166
176
|
};
|
|
177
|
+
console.log('[FullDocScanner] Calling onResult with base64 length:', base64?.length);
|
|
167
178
|
onResult({
|
|
168
179
|
original: finalDoc,
|
|
169
180
|
rectangle: rectangleToUse,
|
|
170
181
|
base64,
|
|
171
182
|
});
|
|
183
|
+
console.log('[FullDocScanner] Resetting state');
|
|
172
184
|
resetState();
|
|
173
185
|
}
|
|
174
186
|
catch (error) {
|
|
@@ -180,33 +192,42 @@ const FullDocScanner = ({ onResult, onClose, detectionConfig, overlayColor = '#3
|
|
|
180
192
|
}
|
|
181
193
|
}, [emitError, onResult, resetState]);
|
|
182
194
|
const handleCapture = (0, react_1.useCallback)((document) => {
|
|
195
|
+
console.log('[FullDocScanner] handleCapture called:', {
|
|
196
|
+
origin: document.origin,
|
|
197
|
+
path: document.path,
|
|
198
|
+
width: document.width,
|
|
199
|
+
height: document.height,
|
|
200
|
+
hasQuad: !!document.quad,
|
|
201
|
+
hasRectangle: !!document.rectangle,
|
|
202
|
+
});
|
|
183
203
|
if (processingCaptureRef.current) {
|
|
204
|
+
console.log('[FullDocScanner] Already processing, skipping');
|
|
184
205
|
return;
|
|
185
206
|
}
|
|
186
207
|
const normalizedDoc = normalizeCapturedDocument(document);
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
}
|
|
198
|
-
processingCaptureRef.current = true;
|
|
199
|
-
processAutoCapture(document);
|
|
200
|
-
}, [manualCapture, processAutoCapture]);
|
|
208
|
+
// 자동 촬영이든 수동 촬영이든 모두 crop 화면으로 이동
|
|
209
|
+
console.log('[FullDocScanner] Moving to crop/preview screen');
|
|
210
|
+
manualCapturePending.current = false;
|
|
211
|
+
processingCaptureRef.current = false;
|
|
212
|
+
cropInitializedRef.current = false;
|
|
213
|
+
setCapturedDoc(normalizedDoc);
|
|
214
|
+
setImageSize(null);
|
|
215
|
+
setCropRectangle(null);
|
|
216
|
+
setScreen('crop');
|
|
217
|
+
}, []);
|
|
201
218
|
const handleCropChange = (0, react_1.useCallback)((rectangle) => {
|
|
202
219
|
setCropRectangle(rectangle);
|
|
203
220
|
}, []);
|
|
204
221
|
const triggerManualCapture = (0, react_1.useCallback)(() => {
|
|
222
|
+
console.log('[FullDocScanner] triggerManualCapture called');
|
|
205
223
|
if (processingCaptureRef.current) {
|
|
224
|
+
console.log('[FullDocScanner] Already processing, skipping manual capture');
|
|
206
225
|
return;
|
|
207
226
|
}
|
|
227
|
+
console.log('[FullDocScanner] Setting manualCapturePending to true');
|
|
208
228
|
manualCapturePending.current = true;
|
|
209
229
|
const capturePromise = docScannerRef.current?.capture();
|
|
230
|
+
console.log('[FullDocScanner] capturePromise:', !!capturePromise);
|
|
210
231
|
if (capturePromise && typeof capturePromise.catch === 'function') {
|
|
211
232
|
capturePromise.catch((error) => {
|
|
212
233
|
manualCapturePending.current = false;
|
|
@@ -214,6 +235,7 @@ const FullDocScanner = ({ onResult, onClose, detectionConfig, overlayColor = '#3
|
|
|
214
235
|
});
|
|
215
236
|
}
|
|
216
237
|
else if (!capturePromise) {
|
|
238
|
+
console.warn('[FullDocScanner] No capture promise returned');
|
|
217
239
|
manualCapturePending.current = false;
|
|
218
240
|
}
|
|
219
241
|
}, []);
|
|
@@ -292,7 +314,7 @@ const FullDocScanner = ({ onResult, onClose, detectionConfig, overlayColor = '#3
|
|
|
292
314
|
}, [onClose, resetState]);
|
|
293
315
|
return (react_1.default.createElement(react_native_1.View, { style: styles.container },
|
|
294
316
|
screen === 'scanner' && (react_1.default.createElement(react_native_1.View, { style: styles.flex },
|
|
295
|
-
react_1.default.createElement(DocScanner_1.DocScanner, { ref: docScannerRef, autoCapture: !manualCapture, overlayColor: overlayColor, showGrid: showGrid, gridColor: resolvedGridColor, gridLineWidth: gridLineWidth, minStableFrames: minStableFrames ?? 6, detectionConfig: detectionConfig, onCapture: handleCapture, showManualCaptureButton:
|
|
317
|
+
react_1.default.createElement(DocScanner_1.DocScanner, { ref: docScannerRef, autoCapture: !manualCapture, overlayColor: overlayColor, showGrid: showGrid, gridColor: resolvedGridColor, gridLineWidth: gridLineWidth, minStableFrames: minStableFrames ?? 6, detectionConfig: detectionConfig, onCapture: handleCapture, showManualCaptureButton: false },
|
|
296
318
|
react_1.default.createElement(react_native_1.View, { style: styles.overlay, pointerEvents: "box-none" },
|
|
297
319
|
react_1.default.createElement(react_native_1.TouchableOpacity, { style: styles.closeButton, onPress: handleClose, accessibilityLabel: mergedStrings.cancel, accessibilityRole: "button" },
|
|
298
320
|
react_1.default.createElement(react_native_1.Text, { style: styles.closeButtonLabel }, "\u00D7")),
|
package/package.json
CHANGED
package/src/FullDocScanner.tsx
CHANGED
|
@@ -208,15 +208,18 @@ export const FullDocScanner: React.FC<FullDocScannerProps> = ({
|
|
|
208
208
|
|
|
209
209
|
const processAutoCapture = useCallback(
|
|
210
210
|
async (document: DocScannerCapture) => {
|
|
211
|
+
console.log('[FullDocScanner] processAutoCapture started');
|
|
211
212
|
manualCapturePending.current = false;
|
|
212
213
|
const normalizedDoc = normalizeCapturedDocument(document);
|
|
213
214
|
const cropManager = NativeModules.CustomCropManager as CustomCropManagerType | undefined;
|
|
214
215
|
|
|
215
216
|
if (!cropManager?.crop) {
|
|
217
|
+
console.error('[FullDocScanner] CustomCropManager.crop is not available');
|
|
216
218
|
emitError(new Error('CustomCropManager.crop is not available'));
|
|
217
219
|
return;
|
|
218
220
|
}
|
|
219
221
|
|
|
222
|
+
console.log('[FullDocScanner] Setting processing to true');
|
|
220
223
|
setProcessing(true);
|
|
221
224
|
|
|
222
225
|
try {
|
|
@@ -250,6 +253,12 @@ export const FullDocScanner: React.FC<FullDocScannerProps> = ({
|
|
|
250
253
|
|
|
251
254
|
const rectangleToUse = scaledRectangle ?? createFullImageRectangle(targetWidth, targetHeight);
|
|
252
255
|
|
|
256
|
+
console.log('[FullDocScanner] Calling CustomCropManager.crop with:', {
|
|
257
|
+
rectangle: rectangleToUse,
|
|
258
|
+
imageUri: ensureFileUri(normalizedDoc.path),
|
|
259
|
+
targetSize: { width: targetWidth, height: targetHeight },
|
|
260
|
+
});
|
|
261
|
+
|
|
253
262
|
const base64 = await new Promise<string>((resolve, reject) => {
|
|
254
263
|
cropManager.crop(
|
|
255
264
|
{
|
|
@@ -263,9 +272,11 @@ export const FullDocScanner: React.FC<FullDocScannerProps> = ({
|
|
|
263
272
|
ensureFileUri(normalizedDoc.path),
|
|
264
273
|
(error: unknown, result: { image: string }) => {
|
|
265
274
|
if (error) {
|
|
275
|
+
console.error('[FullDocScanner] CustomCropManager.crop error:', error);
|
|
266
276
|
reject(error instanceof Error ? error : new Error('Crop failed'));
|
|
267
277
|
return;
|
|
268
278
|
}
|
|
279
|
+
console.log('[FullDocScanner] CustomCropManager.crop success, base64 length:', result.image?.length);
|
|
269
280
|
resolve(result.image);
|
|
270
281
|
},
|
|
271
282
|
);
|
|
@@ -276,12 +287,14 @@ export const FullDocScanner: React.FC<FullDocScannerProps> = ({
|
|
|
276
287
|
rectangle: rectangleToUse,
|
|
277
288
|
};
|
|
278
289
|
|
|
290
|
+
console.log('[FullDocScanner] Calling onResult with base64 length:', base64?.length);
|
|
279
291
|
onResult({
|
|
280
292
|
original: finalDoc,
|
|
281
293
|
rectangle: rectangleToUse,
|
|
282
294
|
base64,
|
|
283
295
|
});
|
|
284
296
|
|
|
297
|
+
console.log('[FullDocScanner] Resetting state');
|
|
285
298
|
resetState();
|
|
286
299
|
} catch (error) {
|
|
287
300
|
setProcessing(false);
|
|
@@ -295,29 +308,33 @@ export const FullDocScanner: React.FC<FullDocScannerProps> = ({
|
|
|
295
308
|
|
|
296
309
|
const handleCapture = useCallback(
|
|
297
310
|
(document: DocScannerCapture) => {
|
|
311
|
+
console.log('[FullDocScanner] handleCapture called:', {
|
|
312
|
+
origin: document.origin,
|
|
313
|
+
path: document.path,
|
|
314
|
+
width: document.width,
|
|
315
|
+
height: document.height,
|
|
316
|
+
hasQuad: !!document.quad,
|
|
317
|
+
hasRectangle: !!document.rectangle,
|
|
318
|
+
});
|
|
319
|
+
|
|
298
320
|
if (processingCaptureRef.current) {
|
|
321
|
+
console.log('[FullDocScanner] Already processing, skipping');
|
|
299
322
|
return;
|
|
300
323
|
}
|
|
301
324
|
|
|
302
325
|
const normalizedDoc = normalizeCapturedDocument(document);
|
|
303
|
-
const wantsManualFlow =
|
|
304
|
-
manualCapture || manualCapturePending.current || document.origin === 'manual';
|
|
305
326
|
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
processingCaptureRef.current = true;
|
|
318
|
-
processAutoCapture(document);
|
|
327
|
+
// 자동 촬영이든 수동 촬영이든 모두 crop 화면으로 이동
|
|
328
|
+
console.log('[FullDocScanner] Moving to crop/preview screen');
|
|
329
|
+
manualCapturePending.current = false;
|
|
330
|
+
processingCaptureRef.current = false;
|
|
331
|
+
cropInitializedRef.current = false;
|
|
332
|
+
setCapturedDoc(normalizedDoc);
|
|
333
|
+
setImageSize(null);
|
|
334
|
+
setCropRectangle(null);
|
|
335
|
+
setScreen('crop');
|
|
319
336
|
},
|
|
320
|
-
[
|
|
337
|
+
[],
|
|
321
338
|
);
|
|
322
339
|
|
|
323
340
|
const handleCropChange = useCallback((rectangle: Rectangle) => {
|
|
@@ -325,17 +342,22 @@ export const FullDocScanner: React.FC<FullDocScannerProps> = ({
|
|
|
325
342
|
}, []);
|
|
326
343
|
|
|
327
344
|
const triggerManualCapture = useCallback(() => {
|
|
345
|
+
console.log('[FullDocScanner] triggerManualCapture called');
|
|
328
346
|
if (processingCaptureRef.current) {
|
|
347
|
+
console.log('[FullDocScanner] Already processing, skipping manual capture');
|
|
329
348
|
return;
|
|
330
349
|
}
|
|
350
|
+
console.log('[FullDocScanner] Setting manualCapturePending to true');
|
|
331
351
|
manualCapturePending.current = true;
|
|
332
352
|
const capturePromise = docScannerRef.current?.capture();
|
|
353
|
+
console.log('[FullDocScanner] capturePromise:', !!capturePromise);
|
|
333
354
|
if (capturePromise && typeof capturePromise.catch === 'function') {
|
|
334
355
|
capturePromise.catch((error: unknown) => {
|
|
335
356
|
manualCapturePending.current = false;
|
|
336
357
|
console.warn('[FullDocScanner] manual capture failed', error);
|
|
337
358
|
});
|
|
338
359
|
} else if (!capturePromise) {
|
|
360
|
+
console.warn('[FullDocScanner] No capture promise returned');
|
|
339
361
|
manualCapturePending.current = false;
|
|
340
362
|
}
|
|
341
363
|
}, []);
|
|
@@ -455,7 +477,7 @@ export const FullDocScanner: React.FC<FullDocScannerProps> = ({
|
|
|
455
477
|
minStableFrames={minStableFrames ?? 6}
|
|
456
478
|
detectionConfig={detectionConfig}
|
|
457
479
|
onCapture={handleCapture}
|
|
458
|
-
showManualCaptureButton
|
|
480
|
+
showManualCaptureButton={false}
|
|
459
481
|
>
|
|
460
482
|
<View style={styles.overlay} pointerEvents="box-none">
|
|
461
483
|
<TouchableOpacity
|