-
Notifications
You must be signed in to change notification settings - Fork 0
/
Button.js
60 lines (51 loc) · 1.59 KB
/
Button.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
60
import React, {
Component,
PropTypes,
Text,
TouchableHighlight,
View,
} from 'react-native';
import {styles} from './Button.style.js';
import Theme from '../../config/theme';
const propTypes = {
enable: PropTypes.bool,
backgroundColor: PropTypes.string,
color: PropTypes.string,
highlightColor: PropTypes.string,
onPress: PropTypes.func
};
const defaultProps = {
enable: true,
backgroundColor: Theme.colors.buttonBackground,
color: Theme.colors.foreground,
highlightColor: Theme.colors.buttonPress,
onPress: () => {}
};
export default class Button extends Component {
constructor(props) {
super(props);
}
onPress() {
if (this.props.enable) {
this.props.onPress();
}
}
render() {
const {enable, backgroundColor, color, highlightColor, text, children, style} = this.props;
let textColor = (enable ? color : Theme.colors.foregroundDisable);
let highlight = enable ? highlightColor : backgroundColor;
let content = text ? (<Text style={[styles.text, {color: textColor}]}>{text}</Text>)
: (<View style={styles.content}>{children}</View>);
return (
<TouchableHighlight
activeOpacity={1} underlayColor={highlight}
onPress={this.onPress.bind(this)}
style={[styles.container, style, {backgroundColor: backgroundColor}]}
>
{ content }
</TouchableHighlight>
);
}
}
Button.propTypes = propTypes;
Button.defaultProps = defaultProps;