@@ -12,33 +12,69 @@ type:_propTypes2.default.string,
1212shape :_propTypes2 . default . string ,
1313gradientStart :_propTypes2 . default . object ,
1414gradientEnd :_propTypes2 . default . object ,
15+ disabledGradientStart :_propTypes2 . default . object ,
16+ disabledGradientEnd :_propTypes2 . default . object ,
17+ disabledOpacity :_propTypes2 . default . number ,
18+ disabled :_propTypes2 . default . bool ,
1519backgroundColors :_propTypes2 . default . array ,
16- buttonStyle :_propTypes2 . default . oneOfType ( [ _propTypes2 . default . number , _propTypes2 . default . object , _propTypes2 . default . array ] ) ,
17- style :_propTypes2 . default . oneOfType ( [ _propTypes2 . default . number , _propTypes2 . default . object , _propTypes2 . default . array ] ) ,
20+ buttonStyle :_propTypes2 . default . any ,
21+ style :_propTypes2 . default . any ,
1822progressSize :_propTypes2 . default . number ,
1923onPress :_propTypes2 . default . func } ) ;
2024
2125
26+
2227var defaultProps = {
2328type :'primary' ,
2429shape :'round' ,
2530backgroundColors :[ '#4DC7A4' , '#66D37A' ] ,
2631gradientStart :{ x :0.5 , y :1 } ,
2732gradientEnd :{ x :1 , y :1 } ,
33+ disabledGradientStart :{ x :0 , y :0 } ,
34+ disabledGradientEnd :{ x :0 , y :0 } ,
35+ disabledOpacity :0.5 ,
36+ disabled :false ,
2837width :null ,
2938height :50 } ; var
3039
3140
32- ButtonComponent = function ( _Component ) { _inherits ( ButtonComponent , _Component ) ; function ButtonComponent ( ) { _classCallCheck ( this , ButtonComponent ) ; return _possibleConstructorReturn ( this , ( ButtonComponent . __proto__ || Object . getPrototypeOf ( ButtonComponent ) ) . apply ( this , arguments ) ) ; } _createClass ( ButtonComponent , [ { key :'shouldComponentUpdate' , value :function shouldComponentUpdate (
41+ ButtonComponent = function ( _Component ) { _inherits ( ButtonComponent , _Component ) ;
42+
43+
44+
45+ function ButtonComponent ( props ) { _classCallCheck ( this , ButtonComponent ) ; var _this = _possibleConstructorReturn ( this , ( ButtonComponent . __proto__ || Object . getPrototypeOf ( ButtonComponent ) ) . call ( this ,
46+ props ) ) ;
3347
48+ _this . state = {
49+ currentButton :_this . getCurrentButton ( props ) } ; return _this ;
3450
51+ } _createClass ( ButtonComponent , [ { key :'componentWillReceiveProps' , value :function componentWillReceiveProps (
52+
53+ nextProps ) {
54+ if ( this . props . buttonState !== nextProps . buttonState ) {
55+ this . setState ( {
56+ currentButton :this . getCurrentButton ( nextProps ) } ) ;
57+
58+ }
59+ } } , { key :'shouldComponentUpdate' , value :function shouldComponentUpdate (
3560
3661nextProps ) {
3762if ( this . props . image !== nextProps . image ) return true ;
3863if ( this . props . text !== nextProps . text ) return true ;
3964if ( this . props . states && this . props . buttonState !== nextProps . buttonState ) return true ;
4065if ( this . props . states && this . props . states [ this . props . buttonState ] . progressFill ) return true ;
4166return false ;
67+ } } , { key :'getCurrentButton' , value :function getCurrentButton (
68+
69+ props ) {
70+ return props . buttonState && props . states ?
71+ props . states [ props . buttonState ] :
72+ props ;
73+ } } , { key :'getProp' , value :function getProp (
74+
75+ propKey ) { var
76+ currentButton = this . state . currentButton ;
77+ return currentButton [ propKey ] || this . props [ propKey ] ;
4278} } , { key :'renderButton' , value :function renderButton ( _ref )
4379
4480{ var _ref$textStyle = _ref . textStyle , textStyle = _ref$textStyle === undefined ?styles . text :_ref$textStyle , _ref$imageStyle = _ref . imageStyle , imageStyle = _ref$imageStyle === undefined ?styles . image :_ref$imageStyle ;
@@ -69,7 +105,7 @@ progressWidth:this.props.progressWidth,
69105progressTintColor :this . props . progressTintColor ,
70106progressBackgroundColor :this . props . progressBackgroundColor ,
71107progressStyle :this . props . progressStyle ,
72- textInsideProgress :this . props . textInsideProgress , __source :{ fileName :_jsxFileName , lineNumber :53 } } ) ;
108+ textInsideProgress :this . props . textInsideProgress , __source :{ fileName :_jsxFileName , lineNumber :89 } } ) ;
73109
74110
75111} else {
@@ -78,7 +114,7 @@ _react2.default.createElement(_Button2.default,{
78114textStyle :this . props . textStyle || textStyle ,
79115imageStyle :this . props . imageStyle || imageStyle ,
80116text :this . props . text ,
81- image :this . props . image , __source :{ fileName :_jsxFileName , lineNumber :77 } } ) ;
117+ image :this . props . image , __source :{ fileName :_jsxFileName , lineNumber :113 } } ) ;
82118
83119
84120}
@@ -87,46 +123,45 @@ return button;
87123} } , { key :'render' , value :function render ( )
88124
89125{
90- var content = void 0 ;
91- var shape = void 0 ;
92-
93- var currentButtonState = this . props . buttonState && this . props . states ?
94- this . props . states [ this . props . buttonState ] :
95- this . props ;
96- var gradientStart = currentButtonState . gradientStart ?
97- currentButtonState . gradientStart :
98- this . props . gradientStart ;
99- var gradientEnd = currentButtonState . gradientEnd ?
100- currentButtonState . gradientEnd :
101- this . props . gradientEnd ;
102- var backgroundColors = currentButtonState . backgroundColors || this . props . backgroundColors ;
103- var type = currentButtonState . type ?currentButtonState . type :this . props . type ;
104-
105- var buttonHeight = currentButtonState . height ?currentButtonState . height :this . props . height ;
106- var buttonWidth = currentButtonState . width ?currentButtonState . width :this . props . width ;
107-
108- if ( this . props . shape === 'round' || this . props . shape === 'circle' ) {
109- shape = {
126+ var style = this . getProp ( 'style' ) ;
127+ var gradientStart = this . getProp ( 'gradientStart' ) ;
128+ var gradientEnd = this . getProp ( 'gradientEnd' ) ;
129+ var disabledGradientStart = this . getProp ( 'disabledGradientStart' ) ;
130+ var disabledGradientEnd = this . getProp ( 'disabledGradientEnd' ) ;
131+ var disabledOpacity = this . getProp ( 'disabledOpacity' ) ;
132+ var disabled = this . getProp ( 'disabled' ) ;
133+ var backgroundColors = this . getProp ( 'backgroundColors' ) ;
134+ var type = this . getProp ( 'type' ) ;
135+ var buttonHeight = this . getProp ( 'height' ) ;
136+ var buttonWidth = this . getProp ( 'width' ) ;
137+ var buttonStyle = this . getProp ( 'buttonStyle' ) ;
138+ var shape = this . getProp ( 'shape' ) ;
139+ var onPress = this . getProp ( 'onPress' ) ;
140+
141+ var shapeStyle = void 0 ;
142+ if ( [ 'round' , 'circle' ] . includes ( shape ) ) {
143+ shapeStyle = {
110144borderRadius :buttonHeight / 2 } ;
111145
112146}
113147
148+ var content = void 0 ;
114149if ( type === 'primary' ) {
115150content =
116151_react2 . default . createElement ( _reactNativeLinearGradient2 . default , {
117- start :gradientStart ,
118- end :gradientEnd ,
152+ start :disabled ? disabledGradientStart : gradientStart ,
153+ end :disabled ? disabledGradientEnd : gradientEnd ,
119154colors :backgroundColors ,
120155collapsable :false ,
121- style :[ styles . button , shape , currentButtonState . buttonStyle ] , __source :{ fileName :_jsxFileName , lineNumber :116 } } ,
156+ style :[ styles . button , shapeStyle , buttonStyle ] , __source :{ fileName :_jsxFileName , lineNumber :151 } } ,
122157
123158this . renderButton ( { textStyle :styles . text } ) ) ;
124159
125160
126161} else {
127162var border = type === 'border' && styles . border ;
128163content =
129- _react2 . default . createElement ( _reactNative . View , { style :[ styles . button , border , shape , currentButtonState . buttonStyle ] , __source :{ fileName :_jsxFileName , lineNumber :129 } } ,
164+ _react2 . default . createElement ( _reactNative . View , { style :[ styles . button , border , shapeStyle , buttonStyle ] , __source :{ fileName :_jsxFileName , lineNumber :164 } } ,
130165this . renderButton ( { textStyle :styles . secondaryText } ) ) ;
131166
132167
@@ -135,9 +170,18 @@ this.renderButton({textStyle:styles.secondaryText}));
135170return (
136171_react2 . default . createElement ( _reactNative . TouchableOpacity , {
137172accessibilityTraits :'button' ,
138- onPress :currentButtonState . onPress ,
173+ disabled :disabled ,
174+ onPress :onPress ,
139175activeOpacity :0.9 ,
140- style :[ styles . container , { width :buttonWidth , height :buttonHeight } , this . props . style ] , __source :{ fileName :_jsxFileName , lineNumber :136 } } ,
176+ style :[
177+ styles . container ,
178+ {
179+ width :buttonWidth ,
180+ height :buttonHeight ,
181+ opacity :disabled ?disabledOpacity :1 } ,
182+
183+ style ] , __source :{ fileName :_jsxFileName , lineNumber :171 } } ,
184+
141185
142186content ) ) ;
143187
0 commit comments