-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSegmentedControl.js
59 lines (52 loc) · 1.94 KB
/
SegmentedControl.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
import React, { Component } from 'react';
import { View, Text } from 'react-native';
import Button from './Button';
class SegmentedControl extends Component {
constructor(props) {
super(props);
this.state = { selectedPage:props.selectedPage };
}
render() {
const defaultButtonColor = '#757575';
const defaultBorderColor = '#fff';
const currentTabTitle = this.props.currentTab;
var leftButtonText = '';
var rightButtonText = '';
if (currentTabTitle==='本地') {
leftButtonText = '最新文章';
rightButtonText = '商場好去處';
} else if (currentTabTitle==='旅遊') {
leftButtonText = '遊玩情報';
rightButtonText = '旅遊快搜';
} else if (currentTabTitle==='飲食') {
leftButtonText = '飲食放題';
rightButtonText = '飲得杯落';
} else if (currentTabTitle==='美容') {
leftButtonText = '美容情報';
rightButtonText = '潮流情報';
}
return (
<View style={styles.containerStyle}>
<Button
buttonColor={this.state.selectedPage===leftButtonText ? this.props.headerColor : defaultButtonColor}
borderColor={this.state.selectedPage===leftButtonText ? this.props.headerColor : defaultBorderColor}
onPress={() => {this.setState({ selectedPage: leftButtonText}); this.props.onPress(leftButtonText); }}>
{leftButtonText}
</Button>
<Button
buttonColor={this.state.selectedPage===rightButtonText ? this.props.headerColor : defaultButtonColor}
borderColor={this.state.selectedPage===rightButtonText ? this.props.headerColor : defaultBorderColor}
onPress={() => {this.setState({ selectedPage: rightButtonText}); this.props.onPress(rightButtonText); }}>
{rightButtonText}
</Button>
</View>
);
}
}
const styles = {
containerStyle: {
flexDirection: 'row',
justifyContent: 'space-around'
}
}
export default SegmentedControl;