@@ -12,44 +12,38 @@ var {
1212 TouchableNativeFeedback,
1313 Platform
1414} = React ;
15- var StyleSheetPropType = require ( 'react-native/Libraries/StyleSheet/StyleSheetPropType' ) ;
16- var TextStylePropTypes = require ( 'react-native/Libraries/Text/TextStylePropTypes' ) ;
1715
1816var Button = React . createClass ( {
1917 propTypes : Object . assign ( { } ,
20- { textStyle : StyleSheetPropType ( TextStylePropTypes ) ,
21- children : PropTypes . string . isRequired ,
22- isLoading : PropTypes . bool ,
23- isDisabled : PropTypes . bool ,
24- activityIndicatorColor : PropTypes . string ,
25- onPress : PropTypes . func ,
26- onLongPress : PropTypes . func ,
27- onPressIn : PropTypes . func ,
28- onPressOut : PropTypes . func } ,
18+ {
19+ textStyle : Text . propTypes . style ,
20+ children : PropTypes . string . isRequired ,
21+ isLoading : PropTypes . bool ,
22+ isDisabled : PropTypes . bool ,
23+ activityIndicatorColor : PropTypes . string ,
24+ onPress : PropTypes . func ,
25+ onLongPress : PropTypes . func ,
26+ onPressIn : PropTypes . func ,
27+ onPressOut : PropTypes . func ,
28+ background : ( TouchableNativeFeedback . propTypes ) ? TouchableNativeFeedback . propTypes . background : PropTypes . any ,
29+ } ,
2930 ) ,
3031
31- _renderInnerText : function ( ) {
32+ statics : {
33+ isAndroid : ( Platform . OS === 'android' ) ,
34+ } ,
35+
36+ _renderInnerTextAndroid : function ( ) {
3237 if ( this . props . isLoading ) {
33- if ( Platform . OS !== 'android' ) {
34- return (
35- < ActivityIndicatorIOS
36- animating = { true }
37- size = 'small'
38- style = { styles . spinner }
39- color = { this . props . activityIndicatorColor || 'black' }
40- />
41- ) ;
42- } else {
43- return (
44- < ProgressBarAndroid
45- style = { [ {
46- height : 20 ,
47- } , styles . spinner ] }
48- styleAttr = 'Inverse'
49- color = { this . props . activityIndicatorColor || 'black' }
50- />
51- ) ;
52- }
38+ return (
39+ < ProgressBarAndroid
40+ style = { [ {
41+ height : 20 ,
42+ } , styles . spinner ] }
43+ styleAttr = 'Inverse'
44+ color = { this . props . activityIndicatorColor || 'black' }
45+ />
46+ ) ;
5347 }
5448 return (
5549 < Text style = { [ styles . textButton , this . props . textStyle ] } >
@@ -58,36 +52,63 @@ var Button = React.createClass({
5852 ) ;
5953 } ,
6054
55+ _renderInnerTextiOS : function ( ) {
56+ if ( this . props . isLoading ) {
57+ return (
58+ < ActivityIndicatorIOS
59+ animating = { true }
60+ size = 'small'
61+ style = { styles . spinner }
62+ color = { this . props . activityIndicatorColor || 'black' }
63+ />
64+ ) ;
65+ }
66+ return (
67+ < Text style = { [ styles . textButton , this . props . textStyle ] } >
68+ { this . props . children }
69+ </ Text >
70+ ) ;
71+ } ,
72+
73+ _renderInnerText : function ( ) {
74+ if ( Button . isAndroid ) {
75+ return this . _renderInnerTextAndroid ( )
76+ }
77+ return this . _renderInnerTextiOS ( )
78+ } ,
79+
6180 render : function ( ) {
62- // Extract Touchable props
63- var touchableProps = {
64- onPress : this . props . onPress ,
65- onPressIn : this . props . onPressIn ,
66- onPressOut : this . props . onPressOut ,
67- onLongPress : this . props . onLongPress
68- } ;
6981 if ( this . props . isDisabled === true || this . props . isLoading === true ) {
7082 return (
7183 < View style = { [ styles . button , this . props . style , styles . opacity ] } >
7284 { this . _renderInnerText ( ) }
7385 </ View >
7486 ) ;
7587 } else {
76- if ( Platform . OS !== 'android' ) {
77- return (
78- < TouchableOpacity { ...touchableProps }
79- style = { [ styles . button , this . props . style ] } >
80- { this . _renderInnerText ( ) }
81- </ TouchableOpacity >
82- ) ;
83- } else {
88+ // Extract Touchable props
89+ var touchableProps = {
90+ onPress : this . props . onPress ,
91+ onPressIn : this . props . onPressIn ,
92+ onPressOut : this . props . onPressOut ,
93+ onLongPress : this . props . onLongPress
94+ } ;
95+ if ( Button . isAndroid ) {
96+ touchableProps = Object . assign ( touchableProps , {
97+ background : this . props . background || TouchableNativeFeedback . SelectableBackground ( )
98+ } ) ;
8499 return (
85- < TouchableNativeFeedback { ...touchableProps }
86- background = { TouchableNativeFeedback . Ripple ( ) } >
100+ < TouchableNativeFeedback { ...touchableProps } >
87101 < Text style = { [ styles . button , this . props . style ] } >
88- { this . _renderInnerText ( ) }
102+ { this . _renderInnerTextAndroid ( ) }
89103 </ Text >
90104 </ TouchableNativeFeedback >
105+ )
106+ } else {
107+ return (
108+ < TouchableOpacity { ...touchableProps }
109+ style = { [ styles . button , this . props . style ] } >
110+ { this . _renderInnerTextiOS ( ) }
111+ </ TouchableOpacity >
91112 ) ;
92113 }
93114 }
0 commit comments