1- import React , { Component , View , TouchableOpacity , Text , StyleSheet , PropTypes , ActivityIndicatorIOS , Platform } from 'react-native'
1+ import React , { Component , 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
55class 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+
615 _renderInnerText ( ) {
716 let children = this . props . children
8- if ( this . props . isLoading ) {
9- if ( Platform . OS === 'ios' ) {
10- return < ActivityIndicatorIOS style = { styles . spinner }
11- animating = { true } size = 'small' color = 'black' />
17+ if ( this . state . isLoading ) {
18+ if ( Platform . OS !== 'android' ) {
19+ return (
20+ < ActivityIndicatorIOS
21+ animating = { true }
22+ size = "small"
23+ style = { styles . spinner }
24+ color = 'black'
25+ />
26+ )
1227 } else {
13- children = 'Loading...'
28+ return (
29+ < ProgressBarAndroid
30+ style = { [ {
31+ height : 20 ,
32+ } , styles . spinner ] }
33+ styleAttr = "Inverse"
34+ />
35+ )
1436 }
1537 }
1638 return (
@@ -28,19 +50,33 @@ class Button extends Component {
2850 onPressOut : this . props . onPressOut ,
2951 onLongPress : this . props . onLongPress
3052 }
31- if ( this . props . isLoading ) {
53+
54+ if ( this . state . isDisabled === true || this . state . isLoading === true ) {
3255 return (
3356 < View style = { [ styles . button , this . props . style , styles . opacity ] } >
3457 { this . _renderInnerText ( ) }
3558 </ View >
3659 )
60+ } else {
61+ return (
62+ < TouchableOpacity { ...touchableProps }
63+ style = { [ styles . button , this . props . style ] } >
64+ { this . _renderInnerText ( ) }
65+ </ TouchableOpacity >
66+ )
3767 }
38- return (
39- < TouchableOpacity { ...touchableProps }
40- style = { [ styles . button , this . props . style ] } >
41- { this . _renderInnerText ( ) }
42- </ TouchableOpacity >
43- )
68+ }
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+ } )
4480 }
4581}
4682
@@ -49,6 +85,7 @@ Button.propTypes = {
4985 textStyle : StyleSheetPropType ( TextStylePropTypes ) ,
5086 children : PropTypes . string . isRequired ,
5187 isLoading : PropTypes . bool ,
88+ isDisabled : PropTypes . bool ,
5289}
5390
5491let styles = StyleSheet . create ( {
0 commit comments