react-native-expo-cropper 1.0.16 → 1.0.17

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.
@@ -37,8 +37,9 @@ function CustomCamera(_ref) {
37
37
  loadingBeforeCapture = _useState4[0],
38
38
  setLoadingBeforeCapture = _useState4[1];
39
39
  var _useState5 = (0, _react.useState)(null),
40
- _useState6 = _slicedToArray(_useState5, 1),
41
- setHasPermission = _useState6[0];
40
+ _useState6 = _slicedToArray(_useState5, 2),
41
+ hasPermission = _useState6[0],
42
+ setHasPermission = _useState6[1];
42
43
  var cameraRef = (0, _react.useRef)(null);
43
44
  (0, _react.useEffect)(function () {
44
45
  _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
@@ -233,34 +233,33 @@ var ImageCropper = function ImageCropper(_ref) {
233
233
  return _regenerator().w(function (_context) {
234
234
  while (1) switch (_context.p = _context.n) {
235
235
  case 0:
236
- // Avoid showing loading modal during confirm to prevent iOS stalls
237
- setShowResult(true);
238
- if (viewRef.current) {
236
+ if (!(!image || !viewRef.current)) {
239
237
  _context.n = 1;
240
238
  break;
241
239
  }
242
- console.error('View ref not ready for capture');
240
+ console.error('Image or view ref not ready for capture');
243
241
  alert('Vue non prête pour la capture');
244
- setShowResult(false);
245
242
  return _context.a(2);
246
243
  case 1:
247
- _context.p = 1;
248
- _context.n = 2;
244
+ setIsLoading(true);
245
+ setShowResult(true);
246
+ _context.p = 2;
247
+ _context.n = 3;
249
248
  return new Promise(function (resolve) {
250
- return requestAnimationFrame(resolve);
249
+ return setTimeout(resolve, 100);
251
250
  });
252
- case 2:
253
- _context.n = 3;
251
+ case 3:
252
+ _context.n = 4;
254
253
  return (0, _reactNativeViewShot.captureRef)(viewRef.current, {
255
254
  format: 'jpg',
256
255
  quality: 1,
257
256
  result: 'tmpfile'
258
257
  });
259
- case 3:
258
+ case 4:
260
259
  capturedUri = _context.v;
261
- _context.n = 4;
260
+ _context.n = 5;
262
261
  return (0, _ImageProcessor.enhanceImage)(capturedUri, addheight);
263
- case 4:
262
+ case 5:
264
263
  finalUri = _context.v;
265
264
  name = "IMAGE XTK".concat(Date.now(), ".jpg");
266
265
  callback = typeof onConfirm === 'function' ? onConfirm : typeof onCrop === 'function' ? onCrop : null;
@@ -269,23 +268,23 @@ var ImageCropper = function ImageCropper(_ref) {
269
268
  return callback(finalUri, name);
270
269
  }, 0);
271
270
  }
272
- _context.n = 6;
271
+ _context.n = 7;
273
272
  break;
274
- case 5:
275
- _context.p = 5;
273
+ case 6:
274
+ _context.p = 6;
276
275
  _t = _context.v;
277
276
  console.error('Erreur lors de la capture :', _t);
278
277
  alert("Erreur lors de la capture !\n".concat(String(_t)));
279
- case 6:
280
- _context.p = 6;
278
+ case 7:
279
+ _context.p = 7;
281
280
  setShowResult(false);
282
281
  setIsLoading(false);
283
282
  setShowFullScreenCapture(false);
284
- return _context.f(6);
285
- case 7:
283
+ return _context.f(7);
284
+ case 8:
286
285
  return _context.a(2);
287
286
  }
288
- }, _callee, null, [[1, 5, 6, 7]]);
287
+ }, _callee, null, [[2, 6, 7, 8]]);
289
288
  }))
290
289
  }, /*#__PURE__*/_react["default"].createElement(_reactNative.Text, {
291
290
  style: _ImageCropperStyles["default"].buttonText
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-expo-cropper",
3
- "version": "1.0.16",
3
+ "version": "1.0.17",
4
4
  "description": "Recadrage polygonal d'images.",
5
5
  "main": "index.js",
6
6
  "author": "PCS AGRI",
@@ -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 [setHasPermission] = useState(null);
18
+ const [hasPermission, setHasPermission] = useState(null);
19
19
  const cameraRef = useRef(null);
20
20
 
21
21
 
@@ -183,18 +183,19 @@ const ImageCropper = ({ onConfirm, onCrop, openCameraFirst, initialImage ,addhei
183
183
  <TouchableOpacity
184
184
  style={styles.button}
185
185
  onPress={async () => {
186
- // Avoid showing loading modal during confirm to prevent iOS stalls
187
- setShowResult(true);
188
-
189
- if (!viewRef.current) {
190
- console.error('View ref not ready for capture');
186
+ // Ensure image exists and view is ready
187
+ if (!image || !viewRef.current) {
188
+ console.error('Image or view ref not ready for capture');
191
189
  alert('Vue non prête pour la capture');
192
- setShowResult(false);
193
190
  return;
194
191
  }
195
192
 
193
+ setIsLoading(true);
194
+ setShowResult(true);
195
+
196
196
  try {
197
- await new Promise((resolve) => requestAnimationFrame(resolve));
197
+ // Give the UI time to update and ensure view is ready
198
+ await new Promise((resolve) => setTimeout(resolve, 100));
198
199
 
199
200
  const capturedUri = await captureRef(viewRef.current, {
200
201
  format: 'jpg',