react-native-expo-cropper 1.0.21 → 1.0.24

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.21",
3
+ "version": "1.0.24",
4
4
  "description": "Recadrage polygonal d'images.",
5
5
  "main": "index.js",
6
6
  "author": "PCS AGRI",
@@ -43,6 +43,12 @@
43
43
  "homepage": "https://github.com/pcsagri/react-native-expo-cropper#readme",
44
44
  "scripts": {
45
45
  "test": "echo \"Error: no test specified\" && exit 1",
46
- "build": "babel src --out-dir dist"
46
+ "build": "babel src --out-dir dist",
47
+ "build:lib": "babel src --out-dir lib"
48
+ },
49
+ "devDependencies": {
50
+ "@babel/cli": "^7.28.3",
51
+ "@babel/core": "^7.28.5",
52
+ "@babel/preset-env": "^7.28.5"
47
53
  }
48
54
  }
@@ -15,7 +15,7 @@ const { width } = Dimensions.get('window');
15
15
  export default function CustomCamera({ onPhotoCaptured}) {
16
16
  const [isReady, setIsReady] = useState(false);
17
17
  const [loadingBeforeCapture, setLoadingBeforeCapture] = useState(false);
18
- const [hasPermission, setHasPermission] = useState(null);
18
+ const [setHasPermission] = useState(null);
19
19
  const cameraRef = useRef(null);
20
20
 
21
21
 
@@ -32,20 +32,24 @@ useEffect(() => {
32
32
  const takePicture = async () => {
33
33
  if (cameraRef.current) {
34
34
  try {
35
- setLoadingBeforeCapture(true);
36
35
 
36
+ setTimeout(() => {
37
+ setLoadingBeforeCapture(true);
38
+ }, 1000);
39
+
40
+
37
41
  const photo = await cameraRef.current.takePictureAsync({
38
- quality: 1,
39
- imageType: 'jpg'
40
- });
42
+ quality: 1,
43
+ shutterSound: false,
44
+ });
41
45
 
46
+
42
47
  onPhotoCaptured(photo.uri);
43
-
48
+
44
49
  setLoadingBeforeCapture(false);
45
50
  } catch (error) {
46
51
  setLoadingBeforeCapture(false);
47
- console.log('Camera takePictureAsync error:', error);
48
- Alert.alert("Erreur", error?.message || 'Capture failed');
52
+ Alert.alert("Erreur");
49
53
  }
50
54
  }
51
55
  };
@@ -1,6 +1,6 @@
1
1
  import styles from './ImageCropperStyles';
2
2
  import React, { useState, useRef, useEffect } from 'react';
3
- import { Modal,View, Image, Dimensions, TouchableOpacity, Animated, Text, InteractionManager } from 'react-native';
3
+ import { Modal,View, Image, Dimensions, TouchableOpacity, Animated, Text } from 'react-native';
4
4
  import Svg, { Path, Circle } from 'react-native-svg';
5
5
  import { captureRef } from 'react-native-view-shot';
6
6
  import CustomCamera from './CustomCamera';
@@ -183,62 +183,32 @@ const ImageCropper = ({ onConfirm, openCameraFirst, initialImage ,addheight}) =>
183
183
  <TouchableOpacity
184
184
  style={styles.button}
185
185
  onPress={async () => {
186
+ // setShowFullScreenCapture(true);
187
+ setIsLoading(true);
188
+ setShowResult(true);
186
189
  try {
187
- // Yield for UI to settle to avoid ref invalidation on iOS
188
- await new Promise(resolve => InteractionManager.runAfterInteractions(resolve));
189
-
190
- // Use JPG + tmpfile for faster iOS snapshots and real file URIs
191
- const captureOptions = { format: 'jpg', quality: 1, result: 'tmpfile' };
192
-
193
- // Timeout wrapper to avoid indefinite hangs
194
- const withTimeout = (promise, ms) =>
195
- new Promise((resolve, reject) => {
196
- const t = setTimeout(() => reject(new Error('captureRef timeout')), ms);
197
- promise.then(
198
- v => { clearTimeout(t); resolve(v); },
199
- e => { clearTimeout(t); reject(e); }
200
- );
201
- });
202
-
203
- // Pass ref object directly (SDK 54 compatibility)
204
- const capturedUri = await withTimeout(captureRef(viewRef, captureOptions), 6000);
205
-
206
- // Try enhancement with a timeout; fallback to captured if slow/fails
207
- const enhanceWithTimeout = (promise, ms) =>
208
- new Promise((resolve) => {
209
- const t = setTimeout(() => resolve(null), ms);
210
- promise.then(uri => { clearTimeout(t); resolve(uri); })
211
- .catch(() => { clearTimeout(t); resolve(null); });
212
- });
213
-
214
- const enhancedUri = await enhanceWithTimeout(enhanceImage(capturedUri, addheight), 4000);
215
-
216
- const resultUri = enhancedUri || capturedUri || image;
217
- const name = `IMAGE XTK${Date.now()}.jpg`;
218
-
219
- if (onConfirm && resultUri) {
220
- // Invoke callback first, then clean up UI to avoid re-render churn
221
- setTimeout(() => onConfirm(resultUri, name), 0);
222
- }
223
-
224
- // Reset UI states after callback
225
- setShowResult(false);
226
- setIsLoading(false);
227
- setShowFullScreenCapture(false);
228
- } catch (error) {
229
- console.error("Erreur lors de la capture :", error);
230
- alert("Erreur lors de la capture !");
231
-
232
- // Fallback to original image to keep UX moving
233
- if (onConfirm && image) {
234
- const name = `IMAGE_FALLBACK_${Date.now()}.jpg`;
235
- setTimeout(() => onConfirm(image, name), 0);
236
- }
237
-
238
- setShowResult(false);
239
- setIsLoading(false);
240
- setShowFullScreenCapture(false);
241
- }
190
+
191
+ const capturedUri = await captureRef(viewRef, {
192
+ format: 'png',
193
+ quality: 1,
194
+ });
195
+
196
+
197
+ const enhancedUri = await enhanceImage(capturedUri ,addheight);
198
+ const name = `IMAGE XTK${Date.now()}.png`;
199
+
200
+
201
+ if (onConfirm) {
202
+ onConfirm(enhancedUri, name);
203
+ }
204
+ } catch (error) {
205
+ console.error("Erreur lors de la capture :", error);
206
+ alert("Erreur lors de la capture !");
207
+ } finally {
208
+ setShowResult(false);
209
+ setIsLoading(false);
210
+ setShowFullScreenCapture(false);
211
+ }
242
212
  }}
243
213
  >
244
214
  <Text style={styles.buttonText}>Confirm</Text>