-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHome.js
112 lines (103 loc) · 1.75 KB
/
Home.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
import React, {Component} from 'react';
import {FlatList, View, StyleSheet, TouchableOpacity} from 'react-native';
export default class Home extends Component {
_onPressItem = () => {
console.log(this.props);
const {navigation: {navigate}} = this.props;
navigate('detail');
};
_renderItem = ({item}) => {
return (
<TouchableOpacity onPress={this._onPressItem}>
<View style={[styles.block, {backgroundColor: item.backgroundColor}]}/>
</TouchableOpacity>
);
};
_keyExtractor = (item) => `${item.id} ${item.backgroundColor}`;
_getItemLayout = (data, index) => {
return {length: 300, offset: 300 * index, index};
};
render() {
const items = [
{
id: 1,
backgroundColor: 'red'
},
{
id: 2,
backgroundColor: 'green'
},
{
id: 3,
backgroundColor: 'blue'
},
{
id: 4,
backgroundColor: 'purple'
},
{
id: 5,
backgroundColor: 'yellow'
},
{
id: 6,
backgroundColor: 'red'
},
{
id: 7,
backgroundColor: 'green'
},
{
id: 8,
backgroundColor: 'blue'
},
{
id: 9,
backgroundColor: 'purple'
},
{
id: 10,
backgroundColor: 'yellow'
},
{
id: 11,
backgroundColor: 'red'
},
{
id: 12,
backgroundColor: 'green'
},
{
id: 13,
backgroundColor: 'blue'
},
{
id: 14,
backgroundColor: 'purple'
},
{
id: 15,
backgroundColor: 'yellow'
}
];
return (
<FlatList
style={styles.flatlist}
windowSize={2}
initialNumToRender={1}
keyExtractor={this._keyExtractor}
data={items}
renderItem={this._renderItem}
getItemLayout={this._getItemLayout}
/>
);
}
}
const styles = StyleSheet.create({
flatlist: {
flex: 1
},
block: {
height: 300
}
});