-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathApp.js
141 lines (132 loc) Β· 3.43 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
import React, { PureComponent } from 'react';
import {
Dimensions,
Text,
ScrollView,
Image,
StyleSheet,
View,
} from 'react-native';
import GridList from 'react-native-grid-list';
export const { width, height } = Dimensions.get('window');
const newImage = {
0: 'business',
1: 'cats',
2: 'city',
3: 'food',
4: 'nightlife',
5: 'fashion',
6: 'people',
7: 'nature',
8: 'animals',
9: 'imageUrl',
};
const image = index => ({
thumbnail: {
uri: `https://lorempixel.com/200/200/${
newImage[index % (Object.keys(newImage).length - 1)]
}`,
},
});
const itemsAnimationAndSeparator = Array.from(Array(5)).map((_, index) =>
image(index),
);
const itemsAnimation = Array.from(Array(6)).map((_, index) => image(index));
const itemsSeparator = Array.from(Array(4)).map((_, index) => image(index));
export default class App extends PureComponent {
renderItemAnimationAndSeparator = ({ item, animation }) => (
<Image
style={styles.imageRadius}
source={item.thumbnail}
onLoad={() => animation.start()}
/>
);
renderItemAnimation = ({ item, animation }) => (
<Image
style={styles.image}
source={item.thumbnail}
onLoad={() => animation.start()}
/>
);
render() {
return (
<ScrollView style={styles.container} showsVerticalScrollIndicator={false}>
{/* AnimationAndSeparator */}
<Text>Separator and animation when loading</Text>
<View style={styles.girdAnimationAndSeparator}>
<GridList
showAnimation
showSeparator
data={itemsAnimationAndSeparator}
numColumns={3}
renderItem={this.renderItemAnimationAndSeparator}
separatorBorderWidth={10}
separatorBorderColor={'black'}
animationInitialBackgroundColor={'white'}
/>
</View>
{/* Animation */}
<Text>Animation when loading</Text>
<View style={styles.girdAnimation}>
<GridList
showAnimation
data={itemsAnimation}
numColumns={4}
renderItem={this.renderItemAnimation}
/>
</View>
{/* Separator with children */}
<Text>Separator with children</Text>
<View style={styles.girdSeparator}>
<GridList
showSeparator
numColumns={2}
separatorBorderWidth={25}
separatorBorderColor={'teal'}
>
<View style={[styles.child, { backgroundColor: 'thistle' }]}>
<Text style={styles.text}>1</Text>
</View>
<Image style={styles.image} source={itemsSeparator[0].thumbnail} />
<View style={[styles.child, { backgroundColor: 'skyblue' }]}>
<Text style={styles.text}>3</Text>
</View>
<Image style={styles.image} source={itemsSeparator[3].thumbnail} />
</GridList>
</View>
</ScrollView>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
margin: '5%',
},
girdAnimationAndSeparator: {
backgroundColor: 'black',
},
girdAnimation: {
backgroundColor: 'tomato',
},
girdSeparator: {
borderWidth: 1,
},
imageRadius: {
width: '100%',
height: '100%',
borderRadius: 10,
},
image: {
width: '100%',
height: '100%',
},
child: {
flex: 1,
justifyContent: 'center',
},
text: {
fontSize: width * 0.2,
textAlign: 'center',
},
});