@dropi/react-native-design-system 0.2.26 → 0.2.28

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.
@@ -4,8 +4,6 @@ type Src = string | number;
4
4
  interface CustomImageProps extends Omit<ImageProps, 'source' | 'placeholder'> {
5
5
  source: Src;
6
6
  fallbackSource?: Src;
7
- placeholderSource?: Src;
8
- retryCount?: number;
9
7
  }
10
8
  export declare const CustomImage: React.FC<CustomImageProps>;
11
9
  export {};
@@ -17,41 +17,28 @@ const normalize = src => {
17
17
  const CustomImage = ({
18
18
  source,
19
19
  fallbackSource,
20
- placeholderSource,
21
- retryCount = 1,
22
20
  contentFit = 'cover',
23
21
  ...rest
24
22
  }) => {
25
- const [currentSource, setCurrentSource] = (0, _react.useState)(source);
26
- const [attempts, setAttempts] = (0, _react.useState)(0);
27
- const [usedFallback, setUsedFallback] = (0, _react.useState)(false);
23
+ const [hasError, setHasError] = (0, _react.useState)(false);
28
24
 
29
- /* sync when source changes */
30
- (0, _react.useEffect)(() => {
31
- setCurrentSource(source);
32
- setAttempts(0);
33
- setUsedFallback(false);
34
- }, [source]);
35
- const handleError = (0, _react.useCallback)(() => {
36
- /* retry first */
37
- if (attempts < retryCount) {
38
- setAttempts(a => a + 1);
39
- setCurrentSource(source);
40
- return;
41
- }
25
+ // If source is empty or there's an error, use fallback
26
+ const displaySource = !source || hasError ? fallbackSource : source;
27
+ const normalizedSource = normalize(displaySource);
28
+ const normalizedPlaceholder = normalize(fallbackSource);
42
29
 
43
- /* fallback once */
44
- if (fallbackSource && !usedFallback) {
45
- setUsedFallback(true);
46
- setCurrentSource(fallbackSource);
47
- }
48
- }, [attempts, retryCount, fallbackSource, usedFallback, source]);
30
+ // If no valid source, don't render anything
31
+ if (!normalizedSource) {
32
+ return null;
33
+ }
49
34
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_expoImage.Image, {
50
35
  ...rest,
51
- source: normalize(currentSource),
52
- placeholder: normalize(placeholderSource),
36
+ source: normalizedSource,
37
+ ...(normalizedPlaceholder && !hasError && {
38
+ placeholder: normalizedPlaceholder
39
+ }),
53
40
  contentFit: contentFit,
54
- onError: handleError
41
+ onError: () => setHasError(true)
55
42
  });
56
43
  };
57
44
  exports.CustomImage = CustomImage;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dropi/react-native-design-system",
3
- "version": "0.2.26",
3
+ "version": "0.2.28",
4
4
  "description": "A React Native package built from scratch",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",