@dropi/react-native-design-system 0.2.27 → 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,47 +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
- // 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);
28
- const [attempts, setAttempts] = (0, _react.useState)(0);
29
- const [usedFallback, setUsedFallback] = (0, _react.useState)(!source && !!fallbackSource);
23
+ const [hasError, setHasError] = (0, _react.useState)(false);
30
24
 
31
- /* sync when source changes */
32
- (0, _react.useEffect)(() => {
33
- const newSource = !source || typeof source === 'string' && source.trim() === '' ? fallbackSource || source : source;
34
- setCurrentSource(newSource);
35
- setAttempts(0);
36
- setUsedFallback(!source && !!fallbackSource);
37
- }, [source, fallbackSource]);
38
- const handleError = (0, _react.useCallback)(() => {
39
- /* retry first */
40
- if (attempts < retryCount) {
41
- setAttempts(a => a + 1);
42
- setCurrentSource(source);
43
- return;
44
- }
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);
45
29
 
46
- /* fallback once */
47
- if (fallbackSource && !usedFallback) {
48
- setUsedFallback(true);
49
- setCurrentSource(fallbackSource);
50
- }
51
- }, [attempts, retryCount, fallbackSource, usedFallback, source]);
52
- const normalizedPlaceholder = normalize(placeholderSource);
30
+ // If no valid source, don't render anything
31
+ if (!normalizedSource) {
32
+ return null;
33
+ }
53
34
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_expoImage.Image, {
54
35
  ...rest,
55
- source: normalize(currentSource),
56
- ...(normalizedPlaceholder && {
36
+ source: normalizedSource,
37
+ ...(normalizedPlaceholder && !hasError && {
57
38
  placeholder: normalizedPlaceholder
58
39
  }),
59
40
  contentFit: contentFit,
60
- onError: handleError
41
+ onError: () => setHasError(true)
61
42
  });
62
43
  };
63
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.27",
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",