SectionSelector.js
2.22 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
'use strict'
import React, {Component} from 'react';
import {
View,
Text,
TouchableOpacity,
Platform,
Dimensions,
StyleSheet,
} from 'react-native';
export default class SectionSelector extends Component {
static propTypes = {
sections: React.PropTypes.arrayOf(
React.PropTypes.shape({
forumCode: React.PropTypes.number.isRequired,
forumName: React.PropTypes.string.isRequired,
}),
),
selectedSectionName: React.PropTypes.string.isRequired,
hidden: React.PropTypes.bool,
onPressSection: React.PropTypes.func,
};
constructor(props) {
super(props);
}
componentDidMount() {
}
render() {
let {sections, selectedSectionName, hidden} = this.props;
if (hidden) {
return null;
}
return (
<View style={styles.container}>
{sections.map((item, i) => {
let backgroundColor = item.forumName === this.props.selectedSectionName ? '#cccccc' : 'white';
return (
<Text
key={i}
style={[styles.text, {backgroundColor,}]}
numberOfLines={1}
onPress={() => {
this.props.onPressSection && this.props.onPressSection(item.forumName, item.forumCode);
}}
>
{item.forumName}
</Text>
);
})}
</View>
);
}
}
let {width, height} = Dimensions.get('window');
const styles = StyleSheet.create({
container: {
flex: 1,
flexDirection: 'row',
flexWrap: 'wrap',
justifyContent: 'space-between',
padding: 15,
paddingTop: 10,
},
text: {
height: 21,
paddingTop: 3,
// minWidth: Math.ceil((width - 45) / 3),
width:((width - 45) / 3),
borderColor: '#a0a0a0',
marginBottom: 10,
backgroundColor: '#f2f2f2',
borderWidth: 0.5,
fontSize: 14,
textAlign: 'center',
},
});