1- import React , { Component , View , TouchableOpacity , Text , StyleSheet , PropTypes , ActivityIndicatorIOS , ProgressBarAndroid , Platform } from 'react-native'
1+ import React , { View , TouchableOpacity , Text , StyleSheet , PropTypes , ActivityIndicatorIOS , ProgressBarAndroid , Platform } from 'react-native'
22import StyleSheetPropType from 'react-native/Libraries/StyleSheet/StyleSheetPropType'
33import TextStylePropTypes from 'react-native/Libraries/Text/TextStylePropTypes'
44
5- class Button extends Component {
6- constructor ( props ) {
7- super ( props )
8-
9- this . state = {
10- isLoading : ( this . props . isLoading === true ? true : false ) ,
11- isDisabled : ( this . props . isDisabled === true ? true : false ) ,
12- }
13- }
14-
5+ class Button extends React . Component {
156 _renderInnerText ( ) {
16- let children = this . props . children
17- if ( this . state . isLoading ) {
7+ if ( this . props . isLoading ) {
188 if ( Platform . OS !== 'android' ) {
199 return (
2010 < ActivityIndicatorIOS
2111 animating = { true }
22- size = " small"
12+ size = ' small'
2313 style = { styles . spinner }
24- color = 'black'
14+ color = { this . props . activityIndicatorColor || 'black' }
2515 />
2616 )
2717 } else {
2818 return (
29- < ProgressBarAndroid
19+ < ProgressBarAndroid
3020 style = { [ {
3121 height : 20 ,
3222 } , styles . spinner ] }
33- styleAttr = " Inverse"
23+ styleAttr = ' Inverse'
3424 />
3525 )
3626 }
3727 }
3828 return (
3929 < Text style = { [ styles . textButton , this . props . textStyle ] } >
40- { children }
30+ { this . props . children }
4131 </ Text >
4232 )
4333 }
@@ -50,8 +40,8 @@ class Button extends Component {
5040 onPressOut : this . props . onPressOut ,
5141 onLongPress : this . props . onLongPress
5242 }
53-
54- if ( this . state . isDisabled === true || this . state . isLoading === true ) {
43+
44+ if ( this . props . isDisabled === true || this . props . isLoading === true ) {
5545 return (
5646 < View style = { [ styles . button , this . props . style , styles . opacity ] } >
5747 { this . _renderInnerText ( ) }
@@ -63,21 +53,9 @@ class Button extends Component {
6353 style = { [ styles . button , this . props . style ] } >
6454 { this . _renderInnerText ( ) }
6555 </ TouchableOpacity >
66- )
56+ )
6757 }
6858 }
69-
70- setIsLoading ( val = false ) {
71- this . setState ( {
72- isLoading : Boolean ( val )
73- } )
74- }
75-
76- setIsDisabled ( val = false ) {
77- this . setState ( {
78- isDisabled : Boolean ( val )
79- } )
80- }
8159}
8260
8361Button . propTypes = {
@@ -86,9 +64,10 @@ Button.propTypes = {
8664 children : PropTypes . string . isRequired ,
8765 isLoading : PropTypes . bool ,
8866 isDisabled : PropTypes . bool ,
67+ activityIndicatorColor : PropTypes . string ,
8968}
9069
91- let styles = StyleSheet . create ( {
70+ const styles = StyleSheet . create ( {
9271 button : {
9372 height : 44 ,
9473 flexDirection : 'row' ,
@@ -106,7 +85,7 @@ let styles = StyleSheet.create({
10685 alignSelf : 'center' ,
10786 } ,
10887 opacity : {
109- opacity : 0.3 ,
88+ opacity : 0.5 ,
11089 } ,
11190} )
11291
0 commit comments