@momo-kits/foundation 0.80.8-beta.13 → 0.80.8-beta.14
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/Application/Components.tsx +1 -0
- package/Image/index.tsx +21 -11
- package/package.json +1 -1
|
@@ -23,6 +23,7 @@ import {
|
|
|
23
23
|
import {scaleSize, Text} from '../Text';
|
|
24
24
|
import {Icon} from '../Icon';
|
|
25
25
|
import {PopupNotify} from '../Popup';
|
|
26
|
+
import Carousel from '@momo-kits/carousel';
|
|
26
27
|
|
|
27
28
|
const Touchable =
|
|
28
29
|
Platform.OS === 'android' ? TouchableGesture : TouchableOpacity;
|
package/Image/index.tsx
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, {useContext, useState} from 'react';
|
|
1
|
+
import React, {useContext, useRef, useState} from 'react';
|
|
2
2
|
import {StyleProp, StyleSheet, View, ViewStyle} from 'react-native';
|
|
3
3
|
import FastImage from 'react-native-fast-image';
|
|
4
4
|
import styles from './styles';
|
|
@@ -14,6 +14,8 @@ export interface ImageProps extends FastImagePropsWithoutStyle {
|
|
|
14
14
|
accessibilityLabel?: string;
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
+
type Status = 'success' | 'loading' | 'error';
|
|
18
|
+
|
|
17
19
|
const Image: React.FC<ImageProps> = ({
|
|
18
20
|
style,
|
|
19
21
|
source,
|
|
@@ -21,19 +23,20 @@ const Image: React.FC<ImageProps> = ({
|
|
|
21
23
|
...rest
|
|
22
24
|
}) => {
|
|
23
25
|
const {theme} = useContext(ApplicationContext);
|
|
24
|
-
const
|
|
25
|
-
const [
|
|
26
|
+
const error = useRef(false);
|
|
27
|
+
const [status, setStatus] = useState<Status>(
|
|
28
|
+
rest.loading ? 'loading' : 'success',
|
|
29
|
+
);
|
|
26
30
|
|
|
27
31
|
/**
|
|
28
32
|
* render content loading | fail | rendered
|
|
29
|
-
* @returns {JSX.Element}
|
|
30
33
|
*/
|
|
31
34
|
const renderContent = () => {
|
|
32
|
-
if (loading ||
|
|
35
|
+
if (status == 'loading' || status == 'error') {
|
|
33
36
|
let content = (
|
|
34
37
|
<Skeleton style={[StyleSheet.absoluteFill, styles.image]} />
|
|
35
38
|
);
|
|
36
|
-
if (
|
|
39
|
+
if (status == 'error') {
|
|
37
40
|
content = (
|
|
38
41
|
<View style={Styles.flexCenter}>
|
|
39
42
|
<Icon source="media_fail" color={theme.colors.text.disable} />
|
|
@@ -63,12 +66,19 @@ const Image: React.FC<ImageProps> = ({
|
|
|
63
66
|
{...rest}
|
|
64
67
|
source={source}
|
|
65
68
|
style={styles.image}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
+
onLoadStart={() => {
|
|
70
|
+
error.current = false;
|
|
71
|
+
}}
|
|
72
|
+
onLoadEnd={() => {
|
|
73
|
+
if (error.current) {
|
|
74
|
+
setStatus('error');
|
|
75
|
+
} else {
|
|
76
|
+
setStatus('success');
|
|
77
|
+
}
|
|
78
|
+
}}
|
|
79
|
+
onError={() => {
|
|
80
|
+
error.current = true;
|
|
69
81
|
}}
|
|
70
|
-
onLoadEnd={() => setLoading(false)}
|
|
71
|
-
onError={() => setFail(true)}
|
|
72
82
|
/>
|
|
73
83
|
{renderContent()}
|
|
74
84
|
</View>
|