@widergy/mobile-ui 2.3.1 → 2.3.3
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/CHANGELOG.md +14 -0
- package/lib/utils/fileUtils.js/index.js +39 -25
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
## [2.3.3](https://github.com/widergy/mobile-ui/compare/v2.3.2...v2.3.3) (2025-12-10)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* file type + resize ([#470](https://github.com/widergy/mobile-ui/issues/470)) ([a71989f](https://github.com/widergy/mobile-ui/commit/a71989f9d5144afe44209a1d135f873c11e084db))
|
|
7
|
+
|
|
8
|
+
## [2.3.2](https://github.com/widergy/mobile-ui/compare/v2.3.1...v2.3.2) (2025-12-10)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* updates npm token ([dd3df0d](https://github.com/widergy/mobile-ui/commit/dd3df0d2ada2c974f40472ed212d8f46cda1134c))
|
|
14
|
+
|
|
1
15
|
## [2.3.1](https://github.com/widergy/mobile-ui/compare/v2.3.0...v2.3.1) (2025-12-05)
|
|
2
16
|
|
|
3
17
|
|
|
@@ -1,9 +1,14 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { manipulateAsync, SaveFormat } from 'expo-image-manipulator';
|
|
2
2
|
|
|
3
3
|
import { IS_IOS } from '../platformUtils/constants';
|
|
4
4
|
|
|
5
|
-
const
|
|
6
|
-
|
|
5
|
+
const COMPRESSION_FACTOR = 0.8;
|
|
6
|
+
|
|
7
|
+
const IMAGE_MANIPULATOR_OPTIONS = {
|
|
8
|
+
base64: false,
|
|
9
|
+
compress: COMPRESSION_FACTOR,
|
|
10
|
+
format: SaveFormat.JPEG
|
|
11
|
+
};
|
|
7
12
|
|
|
8
13
|
export const isImageByUri = uri => {
|
|
9
14
|
const uCaseUri = uri.toUpperCase();
|
|
@@ -11,8 +16,10 @@ export const isImageByUri = uri => {
|
|
|
11
16
|
return uCaseUri.includes('.JPG') || uCaseUri.includes('.JPEG') || uCaseUri.includes('PNG');
|
|
12
17
|
};
|
|
13
18
|
|
|
14
|
-
export const blobToFile = (blob,
|
|
15
|
-
new File([blob], customName || blob.data?.name || blob.name || 'archivo', {
|
|
19
|
+
export const blobToFile = (blob, mimeType, customName) =>
|
|
20
|
+
new File([blob], customName || blob.data?.name || blob.name || 'archivo', {
|
|
21
|
+
type: blob.data?.type || mimeType
|
|
22
|
+
});
|
|
16
23
|
|
|
17
24
|
// We use the XMLHttpRequest API since the fetch API does not behave correctly under new sdks on Android
|
|
18
25
|
export const uriToBlob = uri => {
|
|
@@ -31,29 +38,36 @@ export const uriToBlob = uri => {
|
|
|
31
38
|
});
|
|
32
39
|
};
|
|
33
40
|
|
|
41
|
+
// This function is used to normalize all image files to JPEG
|
|
42
|
+
const handleImageFileToBlob = async uri => {
|
|
43
|
+
let blob = null;
|
|
44
|
+
|
|
45
|
+
try {
|
|
46
|
+
blob = await uriToBlob(uri);
|
|
47
|
+
|
|
48
|
+
const isDataTypeJpeg = blob.data?.type.includes('jpeg');
|
|
49
|
+
|
|
50
|
+
// If the file is already a JPEG, we return it as is
|
|
51
|
+
if (isDataTypeJpeg) return blob;
|
|
52
|
+
|
|
53
|
+
const imageBase = await manipulateAsync(uri, [], IMAGE_MANIPULATOR_OPTIONS);
|
|
54
|
+
|
|
55
|
+
blob = await uriToBlob(imageBase.uri);
|
|
56
|
+
} catch (err) {
|
|
57
|
+
blob = await uriToBlob(uri);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return blob;
|
|
61
|
+
};
|
|
62
|
+
|
|
34
63
|
export const retrieveFile = async (uri, type) => {
|
|
35
64
|
const uriToUse = IS_IOS ? uri.replace('file://', '') : uri;
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
if (type ? type.includes('image') : isImageByUri(uri)) {
|
|
39
|
-
if (ExpoImageManipulator?.manipulateAsync) {
|
|
40
|
-
try {
|
|
41
|
-
const actions = [{ resize: { width: IMG_SIZE, height: IMG_SIZE } }];
|
|
42
|
-
const options = {
|
|
43
|
-
compress: IMG_QUALITY / 100,
|
|
44
|
-
format: ExpoImageManipulator?.SaveFormat?.JPEG ?? 'jpeg',
|
|
45
|
-
base64: false
|
|
46
|
-
};
|
|
47
|
-
const result = await ExpoImageManipulator.manipulateAsync(uri, actions, options);
|
|
48
|
-
blob = await uriToBlob(result.uri);
|
|
49
|
-
} catch (err) {
|
|
50
|
-
blob = await uriToBlob(uriToUse);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
} else {
|
|
54
|
-
blob = await uriToBlob(uriToUse);
|
|
55
|
-
}
|
|
65
|
+
const isImageFile = type ? type.includes('image') : isImageByUri(uri);
|
|
56
66
|
|
|
67
|
+
if (isImageFile) {
|
|
68
|
+
return handleImageFileToBlob(uri);
|
|
69
|
+
}
|
|
70
|
+
const blob = await uriToBlob(uriToUse);
|
|
57
71
|
return blob;
|
|
58
72
|
};
|
|
59
73
|
|
package/package.json
CHANGED