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 +1 -1
- package/src/ImageCropper.js +26 -5
package/package.json
CHANGED
package/src/ImageCropper.js
CHANGED
|
@@ -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
|
-
|
|
112
|
-
const
|
|
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) =>
|
|
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
|
-
|
|
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 ? '
|
|
221
|
+
fill={showResult ? 'white' : 'rgba(255, 255, 255, 0.8)'}
|
|
201
222
|
fillRule="evenodd"
|
|
202
223
|
/>
|
|
203
224
|
{!showResult && points.length > 0 && (
|