react-native-rectangle-doc-scanner 3.61.0 → 3.63.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.
@@ -88,6 +88,13 @@ exports.DocScanner = (0, react_1.forwardRef)(({ onCapture, overlayColor = DEFAUL
88
88
  return Math.min(100, Math.max(0, quality));
89
89
  }, [quality]);
90
90
  const handlePictureTaken = (0, react_1.useCallback)((event) => {
91
+ console.log('[DocScanner] handlePictureTaken called with event:', {
92
+ hasInitialImage: !!event.initialImage,
93
+ hasCroppedImage: !!event.croppedImage,
94
+ hasRectangleCoordinates: !!event.rectangleCoordinates,
95
+ width: event.width,
96
+ height: event.height,
97
+ });
91
98
  setIsAutoCapturing(false);
92
99
  const normalizedRectangle = normalizeRectangle(event.rectangleCoordinates ?? null) ?? lastRectangleRef.current;
93
100
  const quad = normalizedRectangle ? (0, coordinate_1.rectangleToQuad)(normalizedRectangle) : null;
@@ -96,7 +103,15 @@ exports.DocScanner = (0, react_1.forwardRef)(({ onCapture, overlayColor = DEFAUL
96
103
  const initialPath = event.initialImage ?? null;
97
104
  const croppedPath = event.croppedImage ?? null;
98
105
  const editablePath = initialPath ?? croppedPath;
106
+ console.log('[DocScanner] Processing captured image:', {
107
+ origin,
108
+ initialPath,
109
+ croppedPath,
110
+ editablePath,
111
+ hasQuad: !!quad,
112
+ });
99
113
  if (editablePath) {
114
+ console.log('[DocScanner] Calling onCapture callback');
100
115
  onCapture?.({
101
116
  path: editablePath,
102
117
  initialPath,
@@ -108,8 +123,12 @@ exports.DocScanner = (0, react_1.forwardRef)(({ onCapture, overlayColor = DEFAUL
108
123
  origin,
109
124
  });
110
125
  }
126
+ else {
127
+ console.warn('[DocScanner] No editable path available, skipping onCapture');
128
+ }
111
129
  setDetectedRectangle(null);
112
130
  if (captureResolvers.current) {
131
+ console.log('[DocScanner] Resolving capture promise');
113
132
  captureResolvers.current.resolve(event);
114
133
  captureResolvers.current = null;
115
134
  }
@@ -121,42 +140,57 @@ exports.DocScanner = (0, react_1.forwardRef)(({ onCapture, overlayColor = DEFAUL
121
140
  }
122
141
  }, []);
123
142
  const capture = (0, react_1.useCallback)(() => {
143
+ console.log('[DocScanner] capture() called');
124
144
  captureOriginRef.current = 'manual';
125
145
  const instance = scannerRef.current;
126
146
  if (!instance || typeof instance.capture !== 'function') {
147
+ console.error('[DocScanner] Native instance not ready:', {
148
+ hasInstance: !!instance,
149
+ hasCaptureMethod: instance ? typeof instance.capture : 'no instance',
150
+ });
127
151
  captureOriginRef.current = 'auto';
128
152
  return Promise.reject(new Error('DocumentScanner native instance is not ready'));
129
153
  }
130
154
  if (captureResolvers.current) {
155
+ console.warn('[DocScanner] Capture already in progress');
131
156
  captureOriginRef.current = 'auto';
132
157
  return Promise.reject(new Error('capture_in_progress'));
133
158
  }
159
+ console.log('[DocScanner] Calling native capture method...');
134
160
  let result;
135
161
  try {
136
162
  result = instance.capture();
163
+ console.log('[DocScanner] Native capture method called, result type:', typeof result, 'isPromise:', !!(result && typeof result.then === 'function'));
137
164
  }
138
165
  catch (error) {
166
+ console.error('[DocScanner] Native capture threw error:', error);
139
167
  captureOriginRef.current = 'auto';
140
168
  return Promise.reject(error);
141
169
  }
142
170
  if (result && typeof result.then === 'function') {
171
+ console.log('[DocScanner] Native returned a promise, waiting for resolution...');
143
172
  return result
144
173
  .then((payload) => {
174
+ console.log('[DocScanner] Native promise resolved with payload:', payload);
145
175
  handlePictureTaken(payload);
146
176
  return payload;
147
177
  })
148
178
  .catch((error) => {
179
+ console.error('[DocScanner] Native promise rejected:', error);
149
180
  captureOriginRef.current = 'auto';
150
181
  throw error;
151
182
  });
152
183
  }
184
+ console.log('[DocScanner] Native did not return a promise, using callback-based approach');
153
185
  return new Promise((resolve, reject) => {
154
186
  captureResolvers.current = {
155
187
  resolve: (value) => {
188
+ console.log('[DocScanner] Callback resolver called with:', value);
156
189
  captureOriginRef.current = 'auto';
157
190
  resolve(value);
158
191
  },
159
192
  reject: (reason) => {
193
+ console.error('[DocScanner] Callback rejector called with:', reason);
160
194
  captureOriginRef.current = 'auto';
161
195
  reject(reason);
162
196
  },
@@ -206,9 +240,9 @@ exports.DocScanner = (0, react_1.forwardRef)(({ onCapture, overlayColor = DEFAUL
206
240
  }), [capture]);
207
241
  const overlayPolygon = detectedRectangle?.rectangleOnScreen ?? detectedRectangle?.rectangleCoordinates ?? null;
208
242
  const overlayIsActive = autoCapture ? isAutoCapturing : (detectedRectangle?.stableCounter ?? 0) > 0;
209
- const detectionThreshold = autoCapture ? minStableFrames : 9999;
243
+ const detectionThreshold = autoCapture ? minStableFrames : 99999;
210
244
  return (react_1.default.createElement(react_native_1.View, { style: styles.container },
211
- react_1.default.createElement(react_native_document_scanner_1.default, { ref: scannerRef, style: styles.scanner, detectionCountBeforeCapture: detectionThreshold, overlayColor: overlayColor, enableTorch: enableTorch, quality: normalizedQuality, useBase64: useBase64, manualOnly: !autoCapture, detectionConfig: detectionConfig, onPictureTaken: handlePictureTaken, onError: handleError, onRectangleDetect: handleRectangleDetect }),
245
+ react_1.default.createElement(react_native_document_scanner_1.default, { ref: scannerRef, style: styles.scanner, detectionCountBeforeCapture: detectionThreshold, overlayColor: overlayColor, enableTorch: enableTorch, quality: normalizedQuality, useBase64: useBase64, manualOnly: false, detectionConfig: detectionConfig, onPictureTaken: handlePictureTaken, onError: handleError, onRectangleDetect: handleRectangleDetect }),
212
246
  showGrid && overlayPolygon && (react_1.default.createElement(overlay_1.ScannerOverlay, { active: overlayIsActive, color: gridColor ?? overlayColor, lineWidth: gridLineWidth, polygon: overlayPolygon })),
213
247
  showManualCaptureButton && (react_1.default.createElement(react_native_1.TouchableOpacity, { style: styles.button, onPress: handleManualCapture })),
214
248
  children));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-rectangle-doc-scanner",
3
- "version": "3.61.0",
3
+ "version": "3.63.0",
4
4
  "description": "Native-backed document scanner for React Native with customizable overlays.",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",
@@ -150,6 +150,14 @@ export const DocScanner = forwardRef<DocScannerHandle, Props>(
150
150
 
151
151
  const handlePictureTaken = useCallback(
152
152
  (event: PictureEvent) => {
153
+ console.log('[DocScanner] handlePictureTaken called with event:', {
154
+ hasInitialImage: !!event.initialImage,
155
+ hasCroppedImage: !!event.croppedImage,
156
+ hasRectangleCoordinates: !!event.rectangleCoordinates,
157
+ width: event.width,
158
+ height: event.height,
159
+ });
160
+
153
161
  setIsAutoCapturing(false);
154
162
 
155
163
  const normalizedRectangle =
@@ -162,7 +170,16 @@ export const DocScanner = forwardRef<DocScannerHandle, Props>(
162
170
  const croppedPath = event.croppedImage ?? null;
163
171
  const editablePath = initialPath ?? croppedPath;
164
172
 
173
+ console.log('[DocScanner] Processing captured image:', {
174
+ origin,
175
+ initialPath,
176
+ croppedPath,
177
+ editablePath,
178
+ hasQuad: !!quad,
179
+ });
180
+
165
181
  if (editablePath) {
182
+ console.log('[DocScanner] Calling onCapture callback');
166
183
  onCapture?.({
167
184
  path: editablePath,
168
185
  initialPath,
@@ -173,11 +190,14 @@ export const DocScanner = forwardRef<DocScannerHandle, Props>(
173
190
  height: event.height ?? 0,
174
191
  origin,
175
192
  });
193
+ } else {
194
+ console.warn('[DocScanner] No editable path available, skipping onCapture');
176
195
  }
177
196
 
178
197
  setDetectedRectangle(null);
179
198
 
180
199
  if (captureResolvers.current) {
200
+ console.log('[DocScanner] Resolving capture promise');
181
201
  captureResolvers.current.resolve(event);
182
202
  captureResolvers.current = null;
183
203
  }
@@ -193,43 +213,61 @@ export const DocScanner = forwardRef<DocScannerHandle, Props>(
193
213
  }, []);
194
214
 
195
215
  const capture = useCallback((): Promise<PictureEvent> => {
216
+ console.log('[DocScanner] capture() called');
196
217
  captureOriginRef.current = 'manual';
197
218
  const instance = scannerRef.current;
219
+
198
220
  if (!instance || typeof instance.capture !== 'function') {
221
+ console.error('[DocScanner] Native instance not ready:', {
222
+ hasInstance: !!instance,
223
+ hasCaptureMethod: instance ? typeof instance.capture : 'no instance',
224
+ });
199
225
  captureOriginRef.current = 'auto';
200
226
  return Promise.reject(new Error('DocumentScanner native instance is not ready'));
201
227
  }
228
+
202
229
  if (captureResolvers.current) {
230
+ console.warn('[DocScanner] Capture already in progress');
203
231
  captureOriginRef.current = 'auto';
204
232
  return Promise.reject(new Error('capture_in_progress'));
205
233
  }
206
234
 
235
+ console.log('[DocScanner] Calling native capture method...');
207
236
  let result: any;
208
237
  try {
209
238
  result = instance.capture();
239
+ console.log('[DocScanner] Native capture method called, result type:', typeof result, 'isPromise:', !!(result && typeof result.then === 'function'));
210
240
  } catch (error) {
241
+ console.error('[DocScanner] Native capture threw error:', error);
211
242
  captureOriginRef.current = 'auto';
212
243
  return Promise.reject(error);
213
244
  }
245
+
214
246
  if (result && typeof result.then === 'function') {
247
+ console.log('[DocScanner] Native returned a promise, waiting for resolution...');
215
248
  return result
216
249
  .then((payload: PictureEvent) => {
250
+ console.log('[DocScanner] Native promise resolved with payload:', payload);
217
251
  handlePictureTaken(payload);
218
252
  return payload;
219
253
  })
220
254
  .catch((error: unknown) => {
255
+ console.error('[DocScanner] Native promise rejected:', error);
221
256
  captureOriginRef.current = 'auto';
222
257
  throw error;
223
258
  });
224
259
  }
225
260
 
261
+ console.log('[DocScanner] Native did not return a promise, using callback-based approach');
226
262
  return new Promise<PictureEvent>((resolve, reject) => {
227
263
  captureResolvers.current = {
228
264
  resolve: (value) => {
265
+ console.log('[DocScanner] Callback resolver called with:', value);
229
266
  captureOriginRef.current = 'auto';
230
267
  resolve(value);
231
268
  },
232
269
  reject: (reason) => {
270
+ console.error('[DocScanner] Callback rejector called with:', reason);
233
271
  captureOriginRef.current = 'auto';
234
272
  reject(reason);
235
273
  },
@@ -294,7 +332,7 @@ export const DocScanner = forwardRef<DocScannerHandle, Props>(
294
332
  const overlayPolygon = detectedRectangle?.rectangleOnScreen ?? detectedRectangle?.rectangleCoordinates ?? null;
295
333
  const overlayIsActive = autoCapture ? isAutoCapturing : (detectedRectangle?.stableCounter ?? 0) > 0;
296
334
 
297
- const detectionThreshold = autoCapture ? minStableFrames : 9999;
335
+ const detectionThreshold = autoCapture ? minStableFrames : 99999;
298
336
 
299
337
  return (
300
338
  <View style={styles.container}>
@@ -306,7 +344,7 @@ export const DocScanner = forwardRef<DocScannerHandle, Props>(
306
344
  enableTorch={enableTorch}
307
345
  quality={normalizedQuality}
308
346
  useBase64={useBase64}
309
- manualOnly={!autoCapture}
347
+ manualOnly={false}
310
348
  detectionConfig={detectionConfig}
311
349
  onPictureTaken={handlePictureTaken}
312
350
  onError={handleError}