@widergy/mobile-ui 0.32.2 → 0.33.0

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 CHANGED
@@ -1,3 +1,24 @@
1
+ # [0.33.0](https://github.com/widergy/mobile-ui/compare/v0.32.4...v0.33.0) (2022-03-25)
2
+
3
+
4
+ ### Features
5
+
6
+ * allow any mime type ([#217](https://github.com/widergy/mobile-ui/issues/217)) ([9b99614](https://github.com/widergy/mobile-ui/commit/9b99614b93d98e14a57c409f0e7674c5832d1b58))
7
+
8
+ ## [0.32.4](https://github.com/widergy/mobile-ui/compare/v0.32.3...v0.32.4) (2022-03-07)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * round the percentage in progress bar in routes ([#216](https://github.com/widergy/mobile-ui/issues/216)) ([9a1c459](https://github.com/widergy/mobile-ui/commit/9a1c4593fbce214c700bc708aecd16c8b10716cd))
14
+
15
+ ## [0.32.3](https://github.com/widergy/mobile-ui/compare/v0.32.2...v0.32.3) (2022-02-25)
16
+
17
+
18
+ ### Bug Fixes
19
+
20
+ * show image on updates (ImagePicker) ([#213](https://github.com/widergy/mobile-ui/issues/213)) ([1b55704](https://github.com/widergy/mobile-ui/commit/1b55704c7e8a42eb057da35872f85ac8b7d11506))
21
+
1
22
  ## [0.32.2](https://github.com/widergy/mobile-ui/compare/v0.32.1...v0.32.2) (2022-02-11)
2
23
 
3
24
 
@@ -26,37 +26,31 @@ class FilePicker extends Component {
26
26
  onError,
27
27
  onChange,
28
28
  maxFileByteSize,
29
+ avoidRetrieveFile,
29
30
  fileTypeError,
30
31
  allowedPDFUploadSizes,
31
32
  pdfFormatError
32
33
  } = this.props;
33
- const promisePicker = new Promise(async (resolve, reject) => {
34
- try {
35
- const picker = await DocumentPicker.pick({
36
- type: allowedTypes && !onlyPDFAllowed(allowedTypes) ? allowedTypes : DocumentPicker.types.allFiles
37
- });
38
- return resolve(picker[0]);
39
- } catch (error) {
40
- return reject(error);
41
- }
42
- });
43
34
  try {
44
- const document = await promisePicker;
35
+ const documents = await DocumentPicker.pick({
36
+ type: allowedTypes && !onlyPDFAllowed(allowedTypes) ? allowedTypes : DocumentPicker.types.allFiles
37
+ });
38
+ const document = documents[0];
45
39
  const isPDF = document.type.includes('pdf');
46
40
  const isImage = document.type.includes('image');
47
41
  if (onlyPDFAllowed(allowedTypes) && !isPDF) {
48
42
  throw new Error(fileTypeError || 'El tipo de archivo debe ser PDF.');
49
43
  }
50
- if (!isImage && !isImageByUri(document.uri) && !isPDF) {
44
+ if (allowedTypes && !isImage && !isImageByUri(document.uri) && !isPDF) {
51
45
  throw new Error(fileTypeError || 'Tipo de archivo inválido.');
52
46
  }
53
- if (document.size > maxFileByteSize) {
47
+ if (maxFileByteSize && document.size > maxFileByteSize) {
54
48
  onMaxSizeError(document.size, maxFileByteSize);
55
49
  return;
56
50
  }
57
- const file = await retrieveFile(document.uri, document.type);
51
+ const file = !avoidRetrieveFile && (await retrieveFile(document.uri, document.type));
58
52
 
59
- if (isPDF && !isEmpty(allowedPDFUploadSizes)) {
53
+ if (file && isPDF && !isEmpty(allowedPDFUploadSizes)) {
60
54
  const isWrongFormat = await pdfAspectRatioValidation(file, allowedPDFUploadSizes);
61
55
  if (isWrongFormat) {
62
56
  throw new Error(
@@ -68,7 +62,7 @@ class FilePicker extends Component {
68
62
  }
69
63
  }
70
64
  if (onChange) {
71
- onChange({ file });
65
+ onChange(avoidRetrieveFile ? { document } : { file });
72
66
  }
73
67
  this.setState({ fileName: document.name });
74
68
  } catch (err) {
@@ -21,13 +21,21 @@ const ImagePickerComponent = ({
21
21
  pickerOptions,
22
22
  style,
23
23
  filePlaceholder,
24
+ unknownFilename,
24
25
  withMarkdownTitle,
25
26
  markdownStyles,
26
- value
27
+ value,
28
+ urlKey,
29
+ avoidRetrieveFile,
30
+ defaultSource
27
31
  }) => {
28
- const initialFileValues = { source: value?.source, fileName: value?.fileName };
29
- const hasInitialValues = initialFileValues.source && initialFileValues.fileName;
30
- const [image, setImage] = useState(hasInitialValues ? initialFileValues : null);
32
+ const fallbackSource = urlKey ? value[urlKey] : typeof value === 'string' ? value : null;
33
+ const fileValues = {
34
+ source: value?.source ?? fallbackSource,
35
+ fileName: value?.fileName ?? unknownFilename ?? filePlaceholder
36
+ };
37
+ const hasValue = fileValues.source && fileValues.fileName;
38
+ const image = hasValue ? fileValues : null;
31
39
  const [deleteModalOpen, setDeleteModalOpen] = useState(false);
32
40
  const [imageModalOpen, setImageModalOpen] = useState(false);
33
41
  const mergedOptions = { ...options, ...pickerOptions };
@@ -45,21 +53,20 @@ const ImagePickerComponent = ({
45
53
  }
46
54
  const { assets } = response;
47
55
  const item = assets[0];
48
- const file = await retrieveFile(item.uri, item.type);
49
- if (!file) {
56
+ const file = !avoidRetrieveFile && (await retrieveFile(item.uri, item.type));
57
+ if (!avoidRetrieveFile && !file) {
50
58
  onError(response.errorCode);
51
59
  return;
52
60
  }
53
61
 
54
- if (file.size > maxFileByteSize) {
62
+ if (!avoidRetrieveFile && maxFileByteSize && file.size > maxFileByteSize) {
55
63
  onMaxSizeError(file.size, maxFileByteSize);
56
64
  return;
57
65
  }
58
66
 
59
67
  if (onChange) {
60
68
  const fileNameAndSource = { source: item.uri, fileName: item.fileName };
61
- onChange({ file, ...fileNameAndSource });
62
- setImage(fileNameAndSource);
69
+ onChange({ ...fileNameAndSource, ...(!avoidRetrieveFile && { file }) });
63
70
  }
64
71
  });
65
72
  };
@@ -68,7 +75,6 @@ const ImagePickerComponent = ({
68
75
  if (onChange) {
69
76
  onChange(null);
70
77
  }
71
- setImage(null);
72
78
  setDeleteModalOpen(false);
73
79
  };
74
80
 
@@ -102,6 +108,7 @@ const ImagePickerComponent = ({
102
108
  deleteImageModalText={deleteImageModalText}
103
109
  withMarkdownTitle={withMarkdownTitle}
104
110
  markdownStyles={markdownStyles}
111
+ defaultSource={defaultSource}
105
112
  />
106
113
  );
107
114
  };
@@ -33,6 +33,7 @@ const ImagePicker = ({
33
33
  onOpenImageModal,
34
34
  withMarkdownTitle,
35
35
  markdownStyles,
36
+ defaultSource,
36
37
  optionsModal
37
38
  }) => {
38
39
  const [openModalSelection, setOpenModalSelection] = useState(false);
@@ -75,7 +76,12 @@ const ImagePicker = ({
75
76
  {image && (
76
77
  <View style={styles.imageContainer}>
77
78
  <TouchableWithoutFeedback onPress={onOpenImageModal} style={styles.touchable}>
78
- <Image source={{ uri: image.source }} style={styles.image} resizeMode="contain" />
79
+ <Image
80
+ source={{ uri: image.source }}
81
+ style={styles.image}
82
+ resizeMode="contain"
83
+ defaultSource={defaultSource}
84
+ />
79
85
  </TouchableWithoutFeedback>
80
86
  </View>
81
87
  )}
@@ -1 +1,4 @@
1
- export const formatPercentage = value => `${(value * 100).toFixed(0).padStart(3, ' ')}%`;
1
+ export const formatPercentage = value =>
2
+ `${Math.floor(value * 100)
3
+ .toFixed(0)
4
+ .padStart(3, ' ')}%`;
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@widergy/mobile-ui",
3
3
  "description": "Widergy Mobile Components",
4
4
  "author": "widergy",
5
- "version": "0.32.2",
5
+ "version": "0.33.0",
6
6
  "repository": "https://github.com/widergy/mobile-ui.git",
7
7
  "main": "lib/index.js",
8
8
  "files": [
@@ -26,7 +26,7 @@
26
26
  "react": "*",
27
27
  "react-native": "*",
28
28
  "react-native-document-picker": "^3.4.0",
29
- "react-native-image-picker": "^0.28.0",
29
+ "react-native-image-picker": "4.x.x",
30
30
  "react-native-image-resizer": "^1.2.2",
31
31
  "react-native-svg": "*",
32
32
  "react-native-vector-icons": "*"