react-native-expo-cropper 1.0.13 → 1.0.15

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.
@@ -227,52 +227,62 @@ var ImageCropper = function ImageCropper(_ref) {
227
227
  style: _ImageCropperStyles["default"].buttonText
228
228
  }, "Reset")), image && /*#__PURE__*/_react["default"].createElement(_reactNative.TouchableOpacity, {
229
229
  style: _ImageCropperStyles["default"].button,
230
- onPress: /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
231
- var capturedUri, enhancedUri, name, _t;
232
- return _regenerator().w(function (_context) {
233
- while (1) switch (_context.p = _context.n) {
230
+ onPress: /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2() {
231
+ var capturePromise, enhancedUri, name, _t;
232
+ return _regenerator().w(function (_context2) {
233
+ while (1) switch (_context2.p = _context2.n) {
234
234
  case 0:
235
235
  // setShowFullScreenCapture(true);
236
236
  setIsLoading(true);
237
237
  setShowResult(true);
238
- _context.p = 1;
239
- _context.n = 2;
238
+ _context2.p = 1;
239
+ _context2.n = 2;
240
240
  return new Promise(function (resolve) {
241
241
  return requestAnimationFrame(resolve);
242
242
  });
243
243
  case 2:
244
- _context.n = 3;
245
- return (0, _reactNativeViewShot.captureRef)(viewRef, {
246
- format: 'png',
247
- quality: 1
248
- });
249
- case 3:
250
- capturedUri = _context.v;
251
- _context.n = 4;
244
+ capturePromise = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
245
+ var capturedUri;
246
+ return _regenerator().w(function (_context) {
247
+ while (1) switch (_context.n) {
248
+ case 0:
249
+ _context.n = 1;
250
+ return (0, _reactNativeViewShot.captureRef)(viewRef.current, {
251
+ format: 'jpg',
252
+ quality: 1,
253
+ result: 'tmpfile'
254
+ });
255
+ case 1:
256
+ capturedUri = _context.v;
257
+ return _context.a(2, (0, _ImageProcessor.enhanceImage)(capturedUri, addheight));
258
+ }
259
+ }, _callee);
260
+ }))();
261
+ _context2.n = 3;
252
262
  return (0, _ImageProcessor.enhanceImage)(capturedUri, addheight);
253
- case 4:
254
- enhancedUri = _context.v;
263
+ case 3:
264
+ enhancedUri = _context2.v;
255
265
  name = "IMAGE XTK".concat(Date.now(), ".png");
256
266
  if (onConfirm) {
257
267
  onConfirm(enhancedUri, name);
258
268
  }
259
- _context.n = 6;
269
+ _context2.n = 5;
260
270
  break;
261
- case 5:
262
- _context.p = 5;
263
- _t = _context.v;
271
+ case 4:
272
+ _context2.p = 4;
273
+ _t = _context2.v;
264
274
  console.error("Erreur lors de la capture :", _t);
265
275
  alert("Erreur lors de la capture !");
266
- case 6:
267
- _context.p = 6;
276
+ case 5:
277
+ _context2.p = 5;
268
278
  setShowResult(false);
269
279
  setIsLoading(false);
270
280
  setShowFullScreenCapture(false);
271
- return _context.f(6);
272
- case 7:
273
- return _context.a(2);
281
+ return _context2.f(5);
282
+ case 6:
283
+ return _context2.a(2);
274
284
  }
275
- }, _callee, null, [[1, 5, 6, 7]]);
285
+ }, _callee2, null, [[1, 4, 5, 6]]);
276
286
  }))
277
287
  }, /*#__PURE__*/_react["default"].createElement(_reactNative.Text, {
278
288
  style: _ImageCropperStyles["default"].buttonText
@@ -13,7 +13,7 @@ function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.
13
13
  function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; }
14
14
  var enhanceImage = exports.enhanceImage = /*#__PURE__*/function () {
15
15
  var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(uri, addheight) {
16
- var imageInfo, ratio, MAX_TARGET_HEIGHT, targetHeight, newWidth, newHeight, result, _t;
16
+ var imageInfo, ratio, maxHeight, newWidth, newHeight, result, _t;
17
17
  return _regenerator().w(function (_context) {
18
18
  while (1) switch (_context.p = _context.n) {
19
19
  case 0:
@@ -23,9 +23,8 @@ var enhanceImage = exports.enhanceImage = /*#__PURE__*/function () {
23
23
  case 1:
24
24
  imageInfo = _context.v;
25
25
  ratio = imageInfo.height / imageInfo.width;
26
- MAX_TARGET_HEIGHT = Math.min(imageInfo.height, 1600);
27
- targetHeight = typeof addheight === 'number' && addheight > 0 ? Math.min(addheight, MAX_TARGET_HEIGHT) : MAX_TARGET_HEIGHT;
28
- newWidth = Math.round(targetHeight / ratio);
26
+ maxHeight = addheight;
27
+ newWidth = Math.round(maxHeight / ratio);
29
28
  newHeight = Math.round(newWidth * ratio);
30
29
  _context.n = 2;
31
30
  return ImageManipulator.manipulateAsync(uri, [{
@@ -34,8 +33,8 @@ var enhanceImage = exports.enhanceImage = /*#__PURE__*/function () {
34
33
  height: newHeight
35
34
  }
36
35
  }], {
37
- compress: 0.92,
38
- format: ImageManipulator.SaveFormat.JPEG
36
+ compress: 1,
37
+ format: ImageManipulator.SaveFormat.PNG
39
38
  });
40
39
  case 2:
41
40
  result = _context.v;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-expo-cropper",
3
- "version": "1.0.13",
3
+ "version": "1.0.15",
4
4
  "description": "Recadrage polygonal d'images.",
5
5
  "main": "index.js",
6
6
  "author": "PCS AGRI",
@@ -188,11 +188,14 @@ const ImageCropper = ({ onConfirm, openCameraFirst, initialImage ,addheight}) =>
188
188
  setShowResult(true);
189
189
  try {
190
190
  await new Promise((resolve) => requestAnimationFrame(resolve));
191
- const capturedUri = await captureRef(viewRef, {
192
- format: 'png',
193
- quality: 1,
194
- });
195
-
191
+ const capturePromise = (async () => {
192
+ const capturedUri = await captureRef(viewRef.current, {
193
+ format: 'jpg',
194
+ quality: 1,
195
+ result: 'tmpfile',
196
+ });
197
+ return enhanceImage(capturedUri, addheight);
198
+ })();
196
199
 
197
200
  const enhancedUri = await enhanceImage(capturedUri ,addheight);
198
201
  const name = `IMAGE XTK${Date.now()}.png`;
@@ -5,12 +5,8 @@ export const enhanceImage = async (uri , addheight) => {
5
5
  const imageInfo = await ImageManipulator.manipulateAsync(uri, []);
6
6
  const ratio = imageInfo.height / imageInfo.width;
7
7
 
8
- const MAX_TARGET_HEIGHT = Math.min(imageInfo.height, 1600);
9
- const targetHeight = (typeof addheight === 'number' && addheight > 0)
10
- ? Math.min(addheight, MAX_TARGET_HEIGHT)
11
- : MAX_TARGET_HEIGHT;
12
-
13
- const newWidth = Math.round(targetHeight / ratio);
8
+ const maxHeight = addheight;
9
+ const newWidth = Math.round(maxHeight / ratio);
14
10
  const newHeight = Math.round(newWidth * ratio);
15
11
 
16
12
  const result = await ImageManipulator.manipulateAsync(
@@ -19,8 +15,8 @@ export const enhanceImage = async (uri , addheight) => {
19
15
  { resize: { width: newWidth, height: newHeight } },
20
16
  ],
21
17
  {
22
- compress: 0.92,
23
- format: ImageManipulator.SaveFormat.JPEG
18
+ compress: 1,
19
+ format: ImageManipulator.SaveFormat.PNG
24
20
  }
25
21
  );
26
22