Category.js
2.23 KB
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
'use strict';
import React from 'react';
import ReactNative from 'react-native';
const {
Component,
} = React;
const {
View,
Text,
Image,
ListView,
TouchableHighlight,
Dimensions,
StyleSheet,
} = ReactNative;
export default class Category extends Component {
static propTypes = {
content: React.PropTypes.arrayOf(
React.PropTypes.shape({
type: React.PropTypes.string,
thumb: React.PropTypes.number,
title: React.PropTypes.string,
})
),
onPress: React.PropTypes.func,
};
constructor(props) {
super(props);
this._renderRow = this._renderRow.bind(this);
this._pressRow = this._pressRow.bind(this);
let ds = new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2});
this.dataSource = ds.cloneWithRows(this.props.content);
}
_pressRow(rowID) {
this.props.onPress && this.props.onPress(rowID);
}
_renderRow(rowData, sectionID, rowID) {
return (
<TouchableHighlight onPress={() => this._pressRow(rowID)} underlayColor={'white'} >
<View style={styles.row}>
<Image style={styles.thumb} source={rowData.thumb} />
<Text style={styles.text}>
{rowData.title}
</Text>
</View>
</TouchableHighlight>
);
}
render() {
return (
<ListView
contentContainerStyle={styles.container}
dataSource={this.dataSource}
renderRow={this._renderRow}
/>
);
}
}
let {width, height} = Dimensions.get('window');
let styles = StyleSheet.create({
container: {
flex: 1,
flexDirection: 'row',
flexWrap: 'wrap',
justifyContent: 'center',
backgroundColor: 'white',
},
row: {
width: width / 3,
height: 100,
justifyContent: 'center',
alignItems: 'center',
paddingTop: 10,
},
image: {
width: 60,
height: 60,
},
text: {
margin: 8,
fontSize: 12,
color: '#444444',
textAlign: 'center',
},
});