@dropi/react-native-design-system 0.2.26 → 0.2.27
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.
|
@@ -22,16 +22,19 @@ const CustomImage = ({
|
|
|
22
22
|
contentFit = 'cover',
|
|
23
23
|
...rest
|
|
24
24
|
}) => {
|
|
25
|
-
|
|
25
|
+
// If source is empty, use fallback immediately
|
|
26
|
+
const initialSource = !source || typeof source === 'string' && source.trim() === '' ? fallbackSource || source : source;
|
|
27
|
+
const [currentSource, setCurrentSource] = (0, _react.useState)(initialSource);
|
|
26
28
|
const [attempts, setAttempts] = (0, _react.useState)(0);
|
|
27
|
-
const [usedFallback, setUsedFallback] = (0, _react.useState)(
|
|
29
|
+
const [usedFallback, setUsedFallback] = (0, _react.useState)(!source && !!fallbackSource);
|
|
28
30
|
|
|
29
31
|
/* sync when source changes */
|
|
30
32
|
(0, _react.useEffect)(() => {
|
|
31
|
-
|
|
33
|
+
const newSource = !source || typeof source === 'string' && source.trim() === '' ? fallbackSource || source : source;
|
|
34
|
+
setCurrentSource(newSource);
|
|
32
35
|
setAttempts(0);
|
|
33
|
-
setUsedFallback(
|
|
34
|
-
}, [source]);
|
|
36
|
+
setUsedFallback(!source && !!fallbackSource);
|
|
37
|
+
}, [source, fallbackSource]);
|
|
35
38
|
const handleError = (0, _react.useCallback)(() => {
|
|
36
39
|
/* retry first */
|
|
37
40
|
if (attempts < retryCount) {
|
|
@@ -46,10 +49,13 @@ const CustomImage = ({
|
|
|
46
49
|
setCurrentSource(fallbackSource);
|
|
47
50
|
}
|
|
48
51
|
}, [attempts, retryCount, fallbackSource, usedFallback, source]);
|
|
52
|
+
const normalizedPlaceholder = normalize(placeholderSource);
|
|
49
53
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_expoImage.Image, {
|
|
50
54
|
...rest,
|
|
51
55
|
source: normalize(currentSource),
|
|
52
|
-
|
|
56
|
+
...(normalizedPlaceholder && {
|
|
57
|
+
placeholder: normalizedPlaceholder
|
|
58
|
+
}),
|
|
53
59
|
contentFit: contentFit,
|
|
54
60
|
onError: handleError
|
|
55
61
|
});
|