react-native-expo-cropper 1.0.2 → 1.0.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-expo-cropper",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "description": "Recadrage polygonal d'images.",
5
5
  "main": "index.js",
6
6
  "author": "PCS AGRI",
@@ -108,10 +108,31 @@ const ImageCropper = ({ onConfirm, openCameraFirst, initialImage ,addheight}) =>
108
108
  const handleMove = (e) => {
109
109
  if (showResult || selectedPointIndex.current === null) return;
110
110
  const { locationX: moveX, locationY: moveY } = e.nativeEvent;
111
- const boundedX = Math.max(0, Math.min(moveX, imageMeasure.current.width));
112
- const boundedY = Math.max(0, Math.min(moveY, imageMeasure.current.height));
111
+
112
+ const width = imageMeasure.current.width;
113
+ const height = imageMeasure.current.height;
114
+
115
+ // Bound the movement
116
+ const boundedX = Math.max(0, Math.min(moveX, width));
117
+ const boundedY = Math.max(0, Math.min(moveY, height));
118
+
119
+ // Define a threshold — if dragged beyond this, cancel
120
+ const edgeThreshold = 10;
121
+ const isNearEdge =
122
+ boundedX <= edgeThreshold || boundedX >= width - edgeThreshold ||
123
+ boundedY <= edgeThreshold || boundedY >= height - edgeThreshold;
124
+
125
+ if (isNearEdge) {
126
+ // Cancel drag
127
+ selectedPointIndex.current = null;
128
+ return;
129
+ }
130
+
131
+ // Safe to update point
113
132
  setPoints(prev =>
114
- prev.map((p, i) => i === selectedPointIndex.current ? { x: boundedX, y: boundedY } : p)
133
+ prev.map((p, i) =>
134
+ i === selectedPointIndex.current ? { x: boundedX, y: boundedY } : p
135
+ )
115
136
  );
116
137
  };
117
138
 
@@ -149,7 +170,7 @@ const ImageCropper = ({ onConfirm, openCameraFirst, initialImage ,addheight}) =>
149
170
  onPress={async () => {
150
171
  // setShowFullScreenCapture(true);
151
172
  setIsLoading(true);
152
- // setShowResult(true);
173
+ setShowResult(true);
153
174
  try {
154
175
  await new Promise((resolve) => requestAnimationFrame(resolve));
155
176
  const capturedUri = await captureRef(viewRef, {
@@ -197,7 +218,7 @@ const ImageCropper = ({ onConfirm, openCameraFirst, initialImage ,addheight}) =>
197
218
  <Svg style={styles.overlay}>
198
219
  <Path
199
220
  d={`M 0 0 H ${imageMeasure.current.width} V ${imageMeasure.current.height} H 0 Z ${createPath()}`}
200
- fill={showResult ? 'black' : 'rgba(0, 0, 0, 0.7)'}
221
+ fill={showResult ? 'white' : 'rgba(255, 255, 255, 0.8)'}
201
222
  fillRule="evenodd"
202
223
  />
203
224
  {!showResult && points.length > 0 && (