-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathApp.js
executable file
·89 lines (79 loc) · 1.74 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
import React, { Component } from 'react';
import { StyleSheet, View } from 'react-native';
import Grid from 'react-native-grid-component';
const ITEMS_COUNT = 19;
export default class Simple extends Component {
constructor(props) {
super(props);
this.state = {
data: generateRandomColorsArray(ITEMS_COUNT),
refreshing: false
};
}
_renderItem = data => (
<View style={[{ backgroundColor: data }, styles.item]} />
);
_renderPlaceholder = () => <View style={styles.item} />;
render() {
return (
<Grid
style={styles.list}
renderItem={this._renderItem}
renderPlaceholder={this._renderPlaceholder}
data={this.state.data}
numColumns={2}
keyExtractor={(item, index) => index.toString()}
refreshing={this.state.refreshing}
onRefresh={() => {
this.setState({
data: generateRandomColorsArray(ITEMS_COUNT),
refreshing: false
});
}}
onEndReached={() => {
this.setState(({ data }) => ({
data: [...data, ...generateRandomColorsArray(ITEMS_COUNT)]
}));
}}
/>
);
}
}
const styles = StyleSheet.create({
item: {
flex: 1,
height: 160,
margin: 1
},
list: {
flex: 1
}
});
// Helper functions
// thanks materialuicolors.co
const colors = [
'#F44336',
'#E91E63',
'#9C27B0',
'#673AB7',
'#3F51B5',
'#2196F3',
'#03A9F4',
'#00BCD4',
'#009688',
'#4CAF50',
'#8BC34A',
'#CDDC39',
'#FFEB3B',
'#FFC107',
'#FF9800',
'#FF5722',
'#795548',
'#9E9E9E',
'#607D8B'
];
function generateRandomColorsArray(length) {
return Array.from(Array(length)).map(
() => colors[Math.floor(Math.random() * colors.length)]
);
}