@widergy/mobile-ui 0.32.2 → 0.32.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 CHANGED
@@ -1,3 +1,10 @@
1
+ ## [0.32.3](https://github.com/widergy/mobile-ui/compare/v0.32.2...v0.32.3) (2022-02-25)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * show image on updates (ImagePicker) ([#213](https://github.com/widergy/mobile-ui/issues/213)) ([1b55704](https://github.com/widergy/mobile-ui/commit/1b55704c7e8a42eb057da35872f85ac8b7d11506))
7
+
1
8
  ## [0.32.2](https://github.com/widergy/mobile-ui/compare/v0.32.1...v0.32.2) (2022-02-11)
2
9
 
3
10
 
@@ -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
  )}
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.32.3",
6
6
  "repository": "https://github.com/widergy/mobile-ui.git",
7
7
  "main": "lib/index.js",
8
8
  "files": [