Skip to content

Commit 5843252

Browse files
committed
Updated loading states
1 parent 94eeace commit 5843252

File tree

3 files changed

+123
-39
lines changed

3 files changed

+123
-39
lines changed

src/comments/comment.loading.ui.js

Lines changed: 48 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,54 @@
11
import React from 'react';
2-
import { View, StyleSheet } from 'react-native';
2+
import { View, StyleSheet, Animated, Easing } from 'react-native';
33

44
import Separator from 'common/components/separator';
55
import { colors } from 'common/constants';
66

7-
export default () => (
8-
<View style={styles.container}>
9-
<View style={styles.loadingComment} />
10-
<View style={styles.loadingComment} />
11-
<View style={styles.metaRow}>
12-
<View style={styles.metaTextLoadingShort} />
13-
<Separator />
14-
<View style={styles.metaTextLoading} />
15-
<Separator />
16-
<View style={styles.metaTextLoading} />
17-
</View>
18-
</View>
19-
);
7+
class CommentLoading extends React.Component {
8+
constructor(props) {
9+
super(props);
10+
this.state = { fadeAnim: new Animated.Value(0.5) };
11+
}
12+
13+
componentDidMount() {
14+
this.animateLoading();
15+
}
16+
17+
animateLoading() {
18+
Animated.timing(this.state.fadeAnim, {
19+
toValue: 1,
20+
duration: 1500,
21+
easing: Easing.back(),
22+
}).start(() => {
23+
this.setState({ fadeAnim: new Animated.Value(0.5) }, () =>
24+
this.animateLoading()
25+
);
26+
});
27+
}
28+
29+
render() {
30+
const { fadeAnim } = this.state;
31+
return (
32+
<View style={styles.container}>
33+
<Animated.View style={[styles.loadingComment, { opacity: fadeAnim }]} />
34+
<Animated.View style={[styles.loadingComment, { opacity: fadeAnim }]} />
35+
<View style={styles.metaRow}>
36+
<Animated.View
37+
style={[styles.metaTextLoadingShort, { opacity: fadeAnim }]}
38+
/>
39+
<Separator />
40+
<Animated.View
41+
style={[styles.metaTextLoading, { opacity: fadeAnim }]}
42+
/>
43+
<Separator />
44+
<Animated.View
45+
style={[styles.metaTextLoading, { opacity: fadeAnim }]}
46+
/>
47+
</View>
48+
</View>
49+
);
50+
}
51+
}
2052

2153
const styles = StyleSheet.create({
2254
container: {
@@ -49,3 +81,5 @@ const styles = StyleSheet.create({
4981
marginBottom: 3,
5082
},
5183
});
84+
85+
export default CommentLoading;

src/common/components/headline.js

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import React from 'react';
22
import { View, Text, StyleSheet } from 'react-native';
3-
import Separator from 'common/components/separator';
43

4+
import Separator from 'common/components/separator';
5+
import HeadlineLoading from 'common/components/headline.loading.ui';
56
import { colors } from 'common/constants';
67

78
const Headline = ({ _loading, title, by, score, descendants, type }) => {
@@ -25,19 +26,7 @@ const Headline = ({ _loading, title, by, score, descendants, type }) => {
2526
</View>
2627
);
2728
}
28-
return (
29-
<View style={styles.container}>
30-
<View style={styles.loadingTitle} />
31-
<View style={styles.loadingTitle} />
32-
<View style={styles.metaRow}>
33-
<View style={styles.metaTextLoading} />
34-
<Separator />
35-
<View style={styles.metaTextLoading} />
36-
<Separator />
37-
<View style={styles.metaTextLoading} />
38-
</View>
39-
</View>
40-
);
29+
return <HeadlineLoading />;
4130
};
4231

4332
const styles = StyleSheet.create({
@@ -57,24 +46,13 @@ const styles = StyleSheet.create({
5746
fontSize: 17,
5847
fontWeight: 'bold',
5948
},
60-
loadingTitle: {
61-
backgroundColor: colors.loadingTextPlaceholder,
62-
height: 17,
63-
marginTop: 3,
64-
marginBottom: 3,
65-
},
6649
metaRow: {
6750
flex: 0,
6851
flexDirection: 'row',
6952
},
7053
metaText: {
7154
color: 'grey',
7255
},
73-
metaTextLoading: {
74-
backgroundColor: '#999999',
75-
height: 17,
76-
width: 75,
77-
},
7856
});
7957

8058
export default Headline;
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import React from 'react';
2+
import { View, StyleSheet, Animated, Easing } from 'react-native';
3+
import Separator from 'common/components/separator';
4+
5+
import { colors } from 'common/constants';
6+
7+
class HeadlineLoading extends React.Component {
8+
constructor(props) {
9+
super(props);
10+
this.state = { fadeAnim: new Animated.Value(0.5) };
11+
}
12+
animateLoading() {
13+
Animated.timing(this.state.fadeAnim, {
14+
toValue: 1,
15+
duration: 1500,
16+
easing: Easing.back(),
17+
}).start(() => {
18+
this.setState({ fadeAnim: new Animated.Value(0.5) }, () =>
19+
this.animateLoading()
20+
);
21+
});
22+
}
23+
render() {
24+
const { fadeAnim } = this.state;
25+
return (
26+
<View style={styles.container}>
27+
<Animated.View style={[styles.loadingTitle, { opacity: fadeAnim }]} />
28+
<Animated.View style={[styles.loadingTitle, { opacity: fadeAnim }]} />
29+
<View style={styles.metaRow}>
30+
<Animated.View
31+
style={[styles.metaTextLoading, { opacity: fadeAnim }]}
32+
/>
33+
<Separator />
34+
<Animated.View
35+
style={[styles.metaTextLoading, { opacity: fadeAnim }]}
36+
/>
37+
<Separator />
38+
<Animated.View
39+
style={[styles.metaTextLoading, { opacity: fadeAnim }]}
40+
/>
41+
</View>
42+
</View>
43+
);
44+
}
45+
}
46+
47+
const styles = StyleSheet.create({
48+
container: {
49+
paddingTop: 10,
50+
paddingBottom: 10,
51+
borderWidth: 0,
52+
borderColor: '#d6d7da',
53+
borderBottomWidth: 0.5,
54+
},
55+
loadingTitle: {
56+
backgroundColor: colors.loadingTextPlaceholder,
57+
height: 17,
58+
marginTop: 3,
59+
marginBottom: 3,
60+
},
61+
metaRow: {
62+
flex: 0,
63+
flexDirection: 'row',
64+
},
65+
metaTextLoading: {
66+
backgroundColor: '#999999',
67+
height: 17,
68+
width: 75,
69+
},
70+
});
71+
72+
export default HeadlineLoading;

0 commit comments

Comments
 (0)