forked from APSL/react-native-button
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathButton.js
102 lines (95 loc) · 2.18 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
102
'use strict';
var React = require('react-native');
var {
View,
TouchableOpacity,
Text,
StyleSheet,
PropTypes,
ActivityIndicatorIOS,
ProgressBarAndroid,
Platform
} = React;
var Button = React.createClass({
propTypes: Object.assign({},
TouchableOpacity.propTypes,
{textStyle: PropTypes.object,
children: PropTypes.string.isRequired,
isLoading: PropTypes.bool,
isDisabled: PropTypes.bool,
activityIndicatorColor: PropTypes.string},
),
_renderInnerText: function () {
if (this.props.isLoading) {
if (Platform.OS !== 'android') {
return (
<ActivityIndicatorIOS
animating={true}
size='small'
style={styles.spinner}
color={this.props.activityIndicatorColor || 'black'}
/>
);
} else {
return (
<ProgressBarAndroid
style={[{
height: 20,
}, styles.spinner]}
styleAttr='Inverse'
/>
);
}
}
return (
<Text style={[styles.textButton, this.props.textStyle]}>
{this.props.children}
</Text>
);
},
render: function () {
// Extract TouchableOpacity props
var touchableProps = {
onPress: this.props.onPress,
onPressIn: this.props.onPressIn,
onPressOut: this.props.onPressOut,
onLongPress: this.props.onLongPress
};
if (this.props.isDisabled === true || this.props.isLoading === true) {
return (
<View style={[styles.button, this.props.style, styles.opacity]}>
{this._renderInnerText()}
</View>
);
} else {
return (
<TouchableOpacity {...touchableProps}
style={[styles.button, this.props.style]}>
{this._renderInnerText()}
</TouchableOpacity>
);
}
}
});
var styles = StyleSheet.create({
button: {
height: 44,
flexDirection: 'row',
borderWidth: 1,
borderRadius: 8,
marginBottom: 10,
alignSelf: 'stretch',
justifyContent: 'center',
},
textButton: {
fontSize: 18,
alignSelf: 'center',
},
spinner: {
alignSelf: 'center',
},
opacity: {
opacity: 0.5,
},
});
module.exports = Button;