@dropi/react-native-design-system 0.2.25 → 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.
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { ImageProps } from 'expo-image';
|
|
3
|
+
type Src = string | number;
|
|
4
|
+
interface CustomImageProps extends Omit<ImageProps, 'source' | 'placeholder'> {
|
|
5
|
+
source: Src;
|
|
6
|
+
fallbackSource?: Src;
|
|
7
|
+
placeholderSource?: Src;
|
|
8
|
+
retryCount?: number;
|
|
9
|
+
}
|
|
10
|
+
export declare const CustomImage: React.FC<CustomImageProps>;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.CustomImage = void 0;
|
|
7
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
8
|
+
var _expoImage = require("expo-image");
|
|
9
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
10
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
11
|
+
const normalize = src => {
|
|
12
|
+
if (!src) return undefined;
|
|
13
|
+
return typeof src === 'string' ? {
|
|
14
|
+
uri: src
|
|
15
|
+
} : src;
|
|
16
|
+
};
|
|
17
|
+
const CustomImage = ({
|
|
18
|
+
source,
|
|
19
|
+
fallbackSource,
|
|
20
|
+
placeholderSource,
|
|
21
|
+
retryCount = 1,
|
|
22
|
+
contentFit = 'cover',
|
|
23
|
+
...rest
|
|
24
|
+
}) => {
|
|
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);
|
|
30
|
+
|
|
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
|
+
}
|
|
45
|
+
|
|
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);
|
|
53
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_expoImage.Image, {
|
|
54
|
+
...rest,
|
|
55
|
+
source: normalize(currentSource),
|
|
56
|
+
...(normalizedPlaceholder && {
|
|
57
|
+
placeholder: normalizedPlaceholder
|
|
58
|
+
}),
|
|
59
|
+
contentFit: contentFit,
|
|
60
|
+
onError: handleError
|
|
61
|
+
});
|
|
62
|
+
};
|
|
63
|
+
exports.CustomImage = CustomImage;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './CustomImage';
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
var _CustomImage = require("./CustomImage");
|
|
7
|
+
Object.keys(_CustomImage).forEach(function (key) {
|
|
8
|
+
if (key === "default" || key === "__esModule") return;
|
|
9
|
+
if (key in exports && exports[key] === _CustomImage[key]) return;
|
|
10
|
+
Object.defineProperty(exports, key, {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
get: function () {
|
|
13
|
+
return _CustomImage[key];
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
});
|
package/lib/atoms/index.d.ts
CHANGED
package/lib/atoms/index.js
CHANGED
|
@@ -25,6 +25,17 @@ Object.keys(_Buttons).forEach(function (key) {
|
|
|
25
25
|
}
|
|
26
26
|
});
|
|
27
27
|
});
|
|
28
|
+
var _CustomImage = require("./CustomImage");
|
|
29
|
+
Object.keys(_CustomImage).forEach(function (key) {
|
|
30
|
+
if (key === "default" || key === "__esModule") return;
|
|
31
|
+
if (key in exports && exports[key] === _CustomImage[key]) return;
|
|
32
|
+
Object.defineProperty(exports, key, {
|
|
33
|
+
enumerable: true,
|
|
34
|
+
get: function () {
|
|
35
|
+
return _CustomImage[key];
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
});
|
|
28
39
|
var _ProviderBadge = require("./ProviderBadge");
|
|
29
40
|
Object.keys(_ProviderBadge).forEach(function (key) {
|
|
30
41
|
if (key === "default" || key === "__esModule") return;
|