react-native-rectangle-doc-scanner 0.20.0 → 0.22.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.
@@ -91,11 +91,28 @@ const DocScanner = ({ onCapture, overlayColor = '#e7a649', autoCapture = true, m
91
91
  (0, react_1.useEffect)(() => {
92
92
  requestPermission();
93
93
  }, [requestPermission]);
94
+ const lastQuadRef = (0, react_1.useRef)(null);
95
+ const noQuadFramesRef = (0, react_1.useRef)(0);
94
96
  const updateQuad = (0, react_native_worklets_core_1.useRunOnJS)((value) => {
95
97
  if (__DEV__) {
96
98
  console.log('[DocScanner] quad', value);
97
99
  }
98
- setQuad(value);
100
+ if (value) {
101
+ // Found a quad, reset counter and update
102
+ noQuadFramesRef.current = 0;
103
+ lastQuadRef.current = value;
104
+ setQuad(value);
105
+ }
106
+ else {
107
+ // No quad found, keep the last one for a few frames
108
+ noQuadFramesRef.current += 1;
109
+ // Keep the last quad for up to 3 frames
110
+ if (noQuadFramesRef.current > 3) {
111
+ lastQuadRef.current = null;
112
+ setQuad(null);
113
+ }
114
+ // Otherwise, keep showing the last quad
115
+ }
99
116
  }, []);
100
117
  const reportError = (0, react_native_worklets_core_1.useRunOnJS)((step, error) => {
101
118
  const message = error instanceof Error ? error.message : `${error}`;
@@ -53,6 +53,8 @@ const Overlay = ({ quad, color = '#e7a649' }) => {
53
53
  skPath.close();
54
54
  return skPath;
55
55
  }, [quad]);
56
- return (react_1.default.createElement(react_native_skia_1.Canvas, { style: { position: 'absolute', top: 0, left: 0, right: 0, bottom: 0 } }, path && react_1.default.createElement(react_native_skia_1.Path, { path: path, color: color, style: "stroke", strokeWidth: 4 })));
56
+ return (react_1.default.createElement(react_native_skia_1.Canvas, { style: { position: 'absolute', top: 0, left: 0, right: 0, bottom: 0, zIndex: 1000 } }, path && (react_1.default.createElement(react_1.default.Fragment, null,
57
+ react_1.default.createElement(react_native_skia_1.Path, { path: path, color: color, style: "stroke", strokeWidth: 8 }),
58
+ react_1.default.createElement(react_native_skia_1.Path, { path: path, color: "rgba(231, 166, 73, 0.2)", style: "fill" })))));
57
59
  };
58
60
  exports.Overlay = Overlay;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-rectangle-doc-scanner",
3
- "version": "0.20.0",
3
+ "version": "0.22.0",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "repository": {
@@ -96,11 +96,30 @@ export const DocScanner: React.FC<Props> = ({
96
96
  requestPermission();
97
97
  }, [requestPermission]);
98
98
 
99
+ const lastQuadRef = useRef<Point[] | null>(null);
100
+ const noQuadFramesRef = useRef(0);
101
+
99
102
  const updateQuad = useRunOnJS((value: Point[] | null) => {
100
103
  if (__DEV__) {
101
104
  console.log('[DocScanner] quad', value);
102
105
  }
103
- setQuad(value);
106
+
107
+ if (value) {
108
+ // Found a quad, reset counter and update
109
+ noQuadFramesRef.current = 0;
110
+ lastQuadRef.current = value;
111
+ setQuad(value);
112
+ } else {
113
+ // No quad found, keep the last one for a few frames
114
+ noQuadFramesRef.current += 1;
115
+
116
+ // Keep the last quad for up to 3 frames
117
+ if (noQuadFramesRef.current > 3) {
118
+ lastQuadRef.current = null;
119
+ setQuad(null);
120
+ }
121
+ // Otherwise, keep showing the last quad
122
+ }
104
123
  }, []);
105
124
 
106
125
  const reportError = useRunOnJS((step: string, error: unknown) => {
@@ -28,8 +28,13 @@ export const Overlay: React.FC<OverlayProps> = ({ quad, color = '#e7a649' }) =>
28
28
  }, [quad]);
29
29
 
30
30
  return (
31
- <Canvas style={{ position: 'absolute', top: 0, left: 0, right: 0, bottom: 0 }}>
32
- {path && <Path path={path} color={color} style="stroke" strokeWidth={4} />}
31
+ <Canvas style={{ position: 'absolute', top: 0, left: 0, right: 0, bottom: 0, zIndex: 1000 }}>
32
+ {path && (
33
+ <>
34
+ <Path path={path} color={color} style="stroke" strokeWidth={8} />
35
+ <Path path={path} color="rgba(231, 166, 73, 0.2)" style="fill" />
36
+ </>
37
+ )}
33
38
  </Canvas>
34
39
  );
35
40
  };