react-native-rectangle-doc-scanner 3.44.3 → 3.44.4

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.
@@ -57,6 +57,7 @@ const FullDocScanner = ({ onResult, onClose, detectionConfig, overlayColor = '#3
57
57
  const [processing, setProcessing] = (0, react_1.useState)(false);
58
58
  const [croppedImageData, setCroppedImageData] = (0, react_1.useState)(null);
59
59
  const [isGalleryOpen, setIsGalleryOpen] = (0, react_1.useState)(false);
60
+ const [rectangleDetected, setRectangleDetected] = (0, react_1.useState)(false);
60
61
  const resolvedGridColor = gridColor ?? overlayColor;
61
62
  const docScannerRef = (0, react_1.useRef)(null);
62
63
  const manualCapturePending = (0, react_1.useRef)(false);
@@ -213,7 +214,19 @@ const FullDocScanner = ({ onResult, onClose, detectionConfig, overlayColor = '#3
213
214
  }
214
215
  }, [croppedImageData, onResult]);
215
216
  const handleRetake = (0, react_1.useCallback)(() => {
217
+ console.log('[FullDocScanner] Retake - clearing cropped image and resetting scanner');
216
218
  setCroppedImageData(null);
219
+ setProcessing(false);
220
+ setRectangleDetected(false);
221
+ // Reset DocScanner state
222
+ if (docScannerRef.current?.reset) {
223
+ docScannerRef.current.reset();
224
+ }
225
+ }, []);
226
+ const handleRectangleDetect = (0, react_1.useCallback)((event) => {
227
+ // Update button color based on rectangle detection
228
+ const hasGoodRectangle = event.lastDetectionType === 0 && event.rectangleCoordinates !== null;
229
+ setRectangleDetected(hasGoodRectangle);
217
230
  }, []);
218
231
  return (react_1.default.createElement(react_native_1.View, { style: styles.container },
219
232
  croppedImageData ? (
@@ -225,7 +238,7 @@ const FullDocScanner = ({ onResult, onClose, detectionConfig, overlayColor = '#3
225
238
  react_1.default.createElement(react_native_1.Text, { style: styles.confirmButtonText }, mergedStrings.retake)),
226
239
  react_1.default.createElement(react_native_1.TouchableOpacity, { style: [styles.confirmButton, styles.confirmButtonPrimary], onPress: handleConfirm, accessibilityLabel: mergedStrings.confirm, accessibilityRole: "button" },
227
240
  react_1.default.createElement(react_native_1.Text, { style: styles.confirmButtonText }, mergedStrings.confirm))))) : (react_1.default.createElement(react_native_1.View, { style: styles.flex },
228
- react_1.default.createElement(DocScanner_1.DocScanner, { ref: docScannerRef, autoCapture: !manualCapture && !isGalleryOpen, overlayColor: overlayColor, showGrid: showGrid, gridColor: resolvedGridColor, gridLineWidth: gridLineWidth, minStableFrames: minStableFrames ?? 6, detectionConfig: detectionConfig, onCapture: handleCapture, showManualCaptureButton: false },
241
+ react_1.default.createElement(DocScanner_1.DocScanner, { ref: docScannerRef, autoCapture: !manualCapture && !isGalleryOpen, overlayColor: overlayColor, showGrid: showGrid, gridColor: resolvedGridColor, gridLineWidth: gridLineWidth, minStableFrames: minStableFrames ?? 6, detectionConfig: detectionConfig, onCapture: handleCapture, onRectangleDetect: handleRectangleDetect, showManualCaptureButton: false },
229
242
  react_1.default.createElement(react_native_1.View, { style: styles.overlayTop, pointerEvents: "box-none" },
230
243
  react_1.default.createElement(react_native_1.TouchableOpacity, { style: styles.closeButton, onPress: handleClose, accessibilityLabel: mergedStrings.cancel, accessibilityRole: "button" },
231
244
  react_1.default.createElement(react_native_1.Text, { style: styles.closeButtonLabel }, "\u00D7"))),
@@ -237,7 +250,10 @@ const FullDocScanner = ({ onResult, onClose, detectionConfig, overlayColor = '#3
237
250
  enableGallery && (react_1.default.createElement(react_native_1.TouchableOpacity, { style: [styles.galleryButton, processing && styles.buttonDisabled], onPress: handleGalleryPick, disabled: processing, accessibilityLabel: mergedStrings.galleryButton, accessibilityRole: "button" },
238
251
  react_1.default.createElement(react_native_1.Text, { style: styles.galleryButtonText }, "\uD83D\uDCC1"))),
239
252
  react_1.default.createElement(react_native_1.TouchableOpacity, { style: [styles.shutterButton, processing && styles.buttonDisabled], onPress: triggerManualCapture, disabled: processing, accessibilityLabel: mergedStrings.manualHint, accessibilityRole: "button" },
240
- react_1.default.createElement(react_native_1.View, { style: styles.shutterInner })))))),
253
+ react_1.default.createElement(react_native_1.View, { style: [
254
+ styles.shutterInner,
255
+ rectangleDetected && { backgroundColor: overlayColor }
256
+ ] })))))),
241
257
  processing && (react_1.default.createElement(react_native_1.View, { style: styles.processingOverlay },
242
258
  react_1.default.createElement(react_native_1.ActivityIndicator, { size: "large", color: overlayColor }),
243
259
  mergedStrings.processing && (react_1.default.createElement(react_native_1.Text, { style: styles.processingText }, mergedStrings.processing))))));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-rectangle-doc-scanner",
3
- "version": "3.44.3",
3
+ "version": "3.44.4",
4
4
  "description": "Native-backed document scanner for React Native with customizable overlays.",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",
@@ -82,6 +82,7 @@ export const FullDocScanner: React.FC<FullDocScannerProps> = ({
82
82
  const [processing, setProcessing] = useState(false);
83
83
  const [croppedImageData, setCroppedImageData] = useState<{path: string; base64?: string} | null>(null);
84
84
  const [isGalleryOpen, setIsGalleryOpen] = useState(false);
85
+ const [rectangleDetected, setRectangleDetected] = useState(false);
85
86
  const resolvedGridColor = gridColor ?? overlayColor;
86
87
  const docScannerRef = useRef<DocScannerHandle | null>(null);
87
88
  const manualCapturePending = useRef(false);
@@ -276,7 +277,20 @@ export const FullDocScanner: React.FC<FullDocScannerProps> = ({
276
277
  }, [croppedImageData, onResult]);
277
278
 
278
279
  const handleRetake = useCallback(() => {
280
+ console.log('[FullDocScanner] Retake - clearing cropped image and resetting scanner');
279
281
  setCroppedImageData(null);
282
+ setProcessing(false);
283
+ setRectangleDetected(false);
284
+ // Reset DocScanner state
285
+ if (docScannerRef.current?.reset) {
286
+ docScannerRef.current.reset();
287
+ }
288
+ }, []);
289
+
290
+ const handleRectangleDetect = useCallback((event: any) => {
291
+ // Update button color based on rectangle detection
292
+ const hasGoodRectangle = event.lastDetectionType === 0 && event.rectangleCoordinates !== null;
293
+ setRectangleDetected(hasGoodRectangle);
280
294
  }, []);
281
295
 
282
296
  return (
@@ -320,6 +334,7 @@ export const FullDocScanner: React.FC<FullDocScannerProps> = ({
320
334
  minStableFrames={minStableFrames ?? 6}
321
335
  detectionConfig={detectionConfig}
322
336
  onCapture={handleCapture}
337
+ onRectangleDetect={handleRectangleDetect}
323
338
  showManualCaptureButton={false}
324
339
  >
325
340
  <View style={styles.overlayTop} pointerEvents="box-none">
@@ -363,7 +378,10 @@ export const FullDocScanner: React.FC<FullDocScannerProps> = ({
363
378
  accessibilityLabel={mergedStrings.manualHint}
364
379
  accessibilityRole="button"
365
380
  >
366
- <View style={styles.shutterInner} />
381
+ <View style={[
382
+ styles.shutterInner,
383
+ rectangleDetected && { backgroundColor: overlayColor }
384
+ ]} />
367
385
  </TouchableOpacity>
368
386
  </View>
369
387
  </DocScanner>
@@ -474,6 +474,12 @@
474
474
 
475
475
  [weakSelf hideGLKView:NO completion:nil];
476
476
  completionHandler(image, initialImage, rectangleFeature);
477
+ } else {
478
+ // No rectangle detected, return original image
479
+ NSLog(@"[IPDFCameraViewController] No rectangle detected during manual capture, returning original image");
480
+ [weakSelf hideGLKView:NO completion:nil];
481
+ UIImage *initialImage = [UIImage imageWithData:imageData];
482
+ completionHandler(initialImage, initialImage, nil);
477
483
  }
478
484
  } else {
479
485
  [weakSelf hideGLKView:NO completion:nil];