SectionSelector.js
2.36 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
'use strict'
import React, {Component} from 'react';
import {
View,
Text,
TouchableOpacity,
Platform,
Dimensions,
StyleSheet,
} from 'react-native';
import PropTypes from 'prop-types';
export default class SectionSelector extends Component {
static propTypes = {
sections: PropTypes.arrayOf(
PropTypes.shape({
forumCode: PropTypes.number.isRequired,
forumName: PropTypes.string.isRequired,
}),
),
selectedSectionName: PropTypes.string.isRequired,
hidden: PropTypes.bool,
onPressSection: 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 ? '#f2f2f2' : 'white';
return (
<Text
key={i}
style={[styles.text, {backgroundColor,}]}
numberOfLines={1}
suppressHighlighting={true}
onPress={() => {
this.props.onPressSection && this.props.onPressSection(item.forumName, item.forumCode);
this.props.onPressBlurAll && this.props.onPressBlurAll();
}}
>
{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: '#f2f2f2',
marginBottom: 10,
backgroundColor: '#f2f2f2',
borderWidth: 0.5,
fontSize: 14,
textAlign: 'center',
},
});