-
Notifications
You must be signed in to change notification settings - Fork 92
/
Copy pathApp.js
174 lines (163 loc) · 5.39 KB
/
App.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
/* @flow */
import React, { PureComponent, Component } from 'react';
import { View, Text, StyleSheet, Animated, Image, ScrollView, FlatList } from 'react-native';
import { LinearGradient } from 'expo-linear-gradient';
import ShimmerPlaceholder from './src/ShimmerPlaceholder'
const FacebookContent = ({ isReversed, shimmerColors, hasData, hasBorder, randomWidth }) => {
// Handle visible
const [visible, setVisible] = React.useState(false)
const [avatarVisible, setAvatarVisible] = React.useState(false)
React.useEffect(() => {
setTimeout(() => {
hasData && setVisible(true)
}, 2000)
}, [])
// Handle animation
const avatarRef = React.createRef()
const firstLineRef = React.createRef()
const secondLineRef = React.createRef()
const thirdLineRef = React.createRef()
React.useEffect(() => {
const facebookAnimated = Animated.stagger(400, [avatarRef.current.getAnimated(), Animated.parallel([
firstLineRef.current.getAnimated(),
secondLineRef.current.getAnimated(),
thirdLineRef.current.getAnimated()
])])
Animated.loop(facebookAnimated).start();
}, [])
return (
<View>
<View style={{ flexDirection: "row" }}>
<ShimmerPlaceholder
width={80} height={80}
style={{ marginRight: 10 }}
ref={avatarRef}
isReversed={isReversed}
shimmerColors={shimmerColors}
shimmerStyle={[hasBorder && { borderRadius: 40 }]}
stopAutoRun
visible={avatarVisible}
>
{hasData && <Image
style={{ width: 80, height: 80, borderRadius: 100 }}
source={{ uri: 'https://unsplash.it/1000/1000' }}
onLoadEnd={() => setAvatarVisible(true)}
/>}
</ShimmerPlaceholder>
<View style={{ justifyContent: "space-between" }}>
<ShimmerPlaceholder
width={randomWidth ? 250 : 200}
style={{}}
ref={firstLineRef}
isReversed={isReversed}
shimmerColors={shimmerColors}
shimmerStyle={[hasBorder && { borderRadius: 20 }]}
stopAutoRun
visible={visible}
>
<Text style={{ flex: 1, flexWrap: 'wrap', width: 200 }}>
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy
</Text>
</ShimmerPlaceholder>
<ShimmerPlaceholder
width={randomWidth ? 150 : 200}
ref={secondLineRef}
isReversed={isReversed}
shimmerColors={shimmerColors}
shimmerStyle={[hasBorder && { borderRadius: 20 }]}
stopAutoRun
visible={visible}
/>
<ShimmerPlaceholder
width={200}
ref={thirdLineRef}
isReversed={isReversed}
shimmerColors={shimmerColors}
shimmerStyle={[hasBorder && { borderRadius: 20 }]}
stopAutoRun
visible={visible}
/>
</View>
</View>
</View>
)
}
export default () => {
const [visible, setVisible] = React.useState(false)
const [avatarVisible, setAvatarVisible] = React.useState(false)
React.useEffect(() => {
setTimeout(() => {
setVisible(true)
}, 2000)
}, [])
return (
<ScrollView style={styles.container} contentInset={{ bottom: 150 }}>
<Text style={styles.title}> React Native Shimmer Placeholder </Text>
<Text style={styles.sessionTitle}>Simple</Text>
<ShimmerPlaceholder
shimmerStyle={{ borderRadius: 10 }}
/>
<Text style={styles.sessionTitle}>Avatar</Text>
<ShimmerPlaceholder
width={150}
height={150}
shimmerStyle={{ borderRadius: 100 }}
visible={avatarVisible}
>
<Image
style={{ width: 150, height: 150, borderRadius: 100 }}
source={{ uri: 'https://unsplash.it/1000/1000' }}
onLoadEnd={() => setAvatarVisible(true)}
/>
</ShimmerPlaceholder>
<Text style={styles.sessionTitle}>Load text data</Text>
<ShimmerPlaceholder
shimmerStyle={{ borderRadius: 10 }}
visible={visible}
width={350}
>
<Text>
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy
</Text>
</ShimmerPlaceholder>
<ShimmerPlaceholder
shimmerStyle={{ borderRadius: 10, marginTop: 2 }}
width={150}
visible={visible}
/>
<ShimmerPlaceholder
shimmerStyle={{ borderRadius: 10, marginTop: 2 }}
width={250}
visible={visible}
/>
<Text></Text>
<Text style={styles.sessionTitle}>Facebook</Text>
<FacebookContent randomWidth />
<Text style={styles.sessionTitle}>Facebook - color</Text>
<FacebookContent shimmerColors={["#FFBDBA", "#FF9C6D", "#FFBDBA"]} />
<Text style={styles.sessionTitle}>Facebook - load data</Text>
<FacebookContent hasBorder hasData />
<Text style={styles.sessionTitle}>Facebook - Reverse</Text>
<FacebookContent isReversed />
</ScrollView>
)
}
const styles = StyleSheet.create({
container: {
flex: 1,
padding: 16,
marginTop: 60,
},
title: {
fontSize: 20,
marginBottom: 12,
fontWeight: "600",
textAlign: "center",
},
sessionTitle: {
fontSize: 16,
marginTop: 20,
marginBottom: 6,
fontWeight: "600"
}
});