forked from ide/react-native-button
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathButton.js
101 lines (89 loc) · 2.27 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
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';
var React = require('react');
var {
PropTypes,
} = React;
var ReactNative = require('react-native');
var {
StyleSheet,
Text,
TouchableOpacity,
View,
} = ReactNative;
var coalesceNonElementChildren = require('./coalesceNonElementChildren');
var systemButtonOpacity = 0.2;
var Button = React.createClass({
propTypes: {
...TouchableOpacity.propTypes,
containerStyle: View.propTypes.style,
disabled: PropTypes.bool,
style: Text.propTypes.style,
styleDisabled: Text.propTypes.style,
},
render() {
var touchableProps = {
activeOpacity: this._computeActiveOpacity(),
};
if (!this.props.disabled) {
touchableProps.onPress = this.props.onPress;
touchableProps.onPressIn = this.props.onPressIn;
touchableProps.onPressOut = this.props.onPressOut;
touchableProps.onLongPress = this.props.onLongPress;
}
return (
<TouchableOpacity {...touchableProps} testID={this.props.testID} style={this.props.containerStyle}>
{this._renderGroupedChildren()}
</TouchableOpacity>
);
},
_renderGroupedChildren() {
var {disabled} = this.props
var style = [
styles.text,
disabled ? styles.disabledText : null,
this.props.style,
disabled ? this.props.styleDisabled : null,
];
var children = coalesceNonElementChildren(this.props.children, (children, index) => {
return (
<Text key={index} style={style} numberOfLines={this.props.numberOfLines}>
{children}
</Text>
);
});
switch (children.length) {
case 0:
return null;
case 1:
return children[0];
default:
return <View style={styles.group}>{children}</View>;
}
},
_computeActiveOpacity() {
if (this.props.disabled) {
return 1;
}
return this.props.activeOpacity != null ?
this.props.activeOpacity :
systemButtonOpacity;
},
});
var styles = StyleSheet.create({
text: {
color: '#007aff',
fontFamily: '.HelveticaNeueInterface-MediumP4',
fontSize: 17,
fontWeight: 'bold',
textAlign: 'center',
},
disabledText: {
color: '#dcdcdc',
},
group: {
flexDirection: 'row',
justifyContent: 'space-between',
alignItems: 'center',
},
});
module.exports = Button;