-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbutton.js
More file actions
101 lines (82 loc) · 2.1 KB
/
button.js
File metadata and controls
101 lines (82 loc) · 2.1 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
'use strict';
import React from 'react-native';
let {
Component,
Text,
TouchableWithoutFeedback,
StyleSheet,
} = React;
const BUTTON_NORMAL = 'BUTTON_NORMAL';
const BUTTON_HELIGHT = 'BUTTON_HELIGHT';
export default class Button extends Component {
constructor(props) {
super(props);
this.state = {
buttonState: BUTTON_NORMAL,
}
this._pressIn = this._pressIn.bind(this);
this._pressOut = this._pressOut.bind(this);
this._onPress = this._onPress.bind(this);
this._selectStyle = this._selectStyle.bind(this);
this._helightStyle = this._helightStyle.bind(this);
}
render() {
return (
<TouchableWithoutFeedback
onPressIn={this._pressIn}
onPressOut={this._pressOut}
onPress={this._onPress} >
<Text style={[this._selectStyle(), this._helightStyle()]} >
{this.props.title}
</Text>
</TouchableWithoutFeedback>
);
}
_pressIn() {
this.props.pressIn && this.props.pressIn();
this.setState({
buttonState: BUTTON_HELIGHT,
});
}
_pressOut() {
this.props.pressOut && this.props.pressOut();
this.setState({
buttonState: BUTTON_NORMAL,
});
}
_onPress() {
this.props.onPress && this.props.onPress();
}
_selectStyle() {
if(this.props.selected) {
return this.props.selectTitleStyle ? this.props.selectTitleStyle : styles.normalTitle;
}
return styles.normalTitle;
}
_helightStyle() {
if(this.state.buttonState === BUTTON_NORMAL) {
if(this.props.selected) {
return this._selectStyle();
}
return this.props.normalTitleStyle ? this.props.normalTitleStyle : styles.normalTitle;
} else if(this.state.buttonState === BUTTON_HELIGHT) {
return this.props.helightTitleStyle ? this.props.helightTitleStyle : styles.helightTitle;
}
}
}
Button.propTypes = {
title: React.PropTypes.string.isRequired,
selected: React.PropTypes.bool,
normalTitleStyle: React.PropTypes.object,
helightTitleStyle: React.PropTypes.object,
selectTitleStyle: React.PropTypes.object,
onPress: React.PropTypes.func,
};
let styles = StyleSheet.create({
normalTitle: {
color: 'black',
},
helightTitle: {
color: 'gray',
},
});