CalendarModeSelector.js
2.41 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
103
104
105
106
107
108
'use strict';
import React from 'react';
import ReactNative from 'react-native';
const {
Component,
} = React;
const {
StyleSheet,
TouchableOpacity,
View,
Text,
Dimensions,
} = ReactNative;
export default class CalendarModeSelector extends Component {
static propTypes = {
selectMode: React.PropTypes.oneOf(['day', 'week', 'month']).isRequired,
onSelect: React.PropTypes.func,
};
constructor(props) {
super(props);
this.onSelect = this.onSelect.bind(this);
}
onSelect(type) {
this.props.onSelect && this.props.onSelect(type);
}
render() {
return (
<View style={styles.container}>
<View style={styles.seprator2} />
{this.props.calendarModes.map((item, i) => {
let color = item.type === this.props.selectMode ? styles.selectText : styles.normalText;
return (
<TouchableOpacity key={i} onPress={() => this.onSelect(item.type)}>
<Text style={[styles.text, color]}>{item.text}</Text>
</TouchableOpacity>
);
})}
<View style={styles.seprator3} />
<View style={styles.seprator4} />
</View>
);
}
}
let {width, height} = Dimensions.get('window');
let styles = StyleSheet.create({
container: {
flexDirection: 'row',
flexWrap: 'wrap',
justifyContent: 'center',
alignItems: 'center',
backgroundColor: 'white',
height: 45,
},
text: {
fontSize: 14,
textAlign: 'center',
width: width / 3,
},
normalText: {
color: '#B0B0B0',
},
selectText: {
color: '#444444',
},
seprator1: {
width: width,
height: 0.5,
backgroundColor: '#B0B0B0',
position: 'absolute',
},
seprator2: {
width: width,
height: 0.5,
top: 44,
backgroundColor: '#B0B0B0',
position: 'absolute',
},
seprator3: {
width: 0.5,
height: 15,
top: 15,
left: width / 3,
backgroundColor: '#B0B0B0',
position: 'absolute',
},
seprator4: {
width: 0.5,
height: 15,
top: 15,
left: width * 2 / 3,
backgroundColor: '#B0B0B0',
position: 'absolute',
},
});