Skip to content

Commit 9e2b5d7

Browse files
committed
fix #26 and update snapshots
1 parent b76f845 commit 9e2b5d7

6 files changed

Lines changed: 31 additions & 10 deletions

File tree

__tests__/__snapshots__/ButtonComponent.test.js.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ exports[`renders correctly 1`] = `
6060
"borderRadius": 25,
6161
},
6262
undefined,
63+
null,
6364
]
6465
}
6566
>

__tests__/__snapshots__/CircleButton.test.js.snap

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ exports[`Circle Button renders CircleButton correctly with multi states 1`] = `
6060
"borderRadius": 50,
6161
},
6262
undefined,
63+
null,
6364
]
6465
}
6566
>
@@ -217,6 +218,7 @@ exports[`Circle Button renders CircleButton correctly with one state 1`] = `
217218
"borderRadius": 50,
218219
},
219220
undefined,
221+
null,
220222
]
221223
}
222224
>

__tests__/__snapshots__/RectangleButton.test.js.snap

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ exports[`Circle Button renders RectangleButton correctly with multi states 1`] =
5858
},
5959
undefined,
6060
undefined,
61+
null,
6162
]
6263
}
6364
>
@@ -213,6 +214,7 @@ exports[`Circle Button renders RectangleButton correctly with one state 1`] = `
213214
},
214215
undefined,
215216
undefined,
217+
null,
216218
]
217219
}
218220
>

__tests__/__snapshots__/RoundButton.test.js.snap

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ exports[`Circle Button renders RoundButton correctly with multi states 1`] = `
6060
"borderRadius": 25,
6161
},
6262
undefined,
63+
null,
6364
]
6465
}
6566
>
@@ -217,6 +218,7 @@ exports[`Circle Button renders RoundButton correctly with one state 1`] = `
217218
"borderRadius": 25,
218219
},
219220
undefined,
221+
null,
220222
]
221223
}
222224
>

dist/ButtonComponent.js

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,13 @@ currentButton:this.getCurrentButton(nextProps)});
6161
nextProps){
6262
if(this.props.image!==nextProps.image)return true;
6363
if(this.props.text!==nextProps.text)return true;
64+
if(this.props.disabled!==nextProps.disabled)return true;
6465
if(this.props.states&&this.props.buttonState!==nextProps.buttonState)return true;
6566
if(this.props.states&&this.props.states[this.props.buttonState].progressFill)return true;
67+
if(
68+
this.props.states&&
69+
this.props.states[this.props.buttonState].disabled!==nextProps.states[nextProps.buttonState].disabled)
70+
return true;
6671
return false;
6772
}},{key:'getCurrentButton',value:function getCurrentButton(
6873

@@ -105,7 +110,7 @@ progressWidth:this.props.progressWidth,
105110
progressTintColor:this.props.progressTintColor,
106111
progressBackgroundColor:this.props.progressBackgroundColor,
107112
progressStyle:this.props.progressStyle,
108-
textInsideProgress:this.props.textInsideProgress,__source:{fileName:_jsxFileName,lineNumber:89}});
113+
textInsideProgress:this.props.textInsideProgress,__source:{fileName:_jsxFileName,lineNumber:94}});
109114

110115

111116
}else{
@@ -114,7 +119,7 @@ _react2.default.createElement(_Button2.default,{
114119
textStyle:this.props.textStyle||textStyle,
115120
imageStyle:this.props.imageStyle||imageStyle,
116121
text:this.props.text,
117-
image:this.props.image,__source:{fileName:_jsxFileName,lineNumber:113}});
122+
image:this.props.image,__source:{fileName:_jsxFileName,lineNumber:118}});
118123

119124

120125
}
@@ -137,6 +142,9 @@ var buttonWidth=this.getProp('width');
137142
var buttonStyle=this.getProp('buttonStyle');
138143
var shape=this.getProp('shape');
139144
var onPress=this.getProp('onPress');
145+
var disabledStyle=disabled?
146+
{opacity:disabledOpacity}:
147+
null;
140148

141149
var shapeStyle=void 0;
142150
if(['round','circle'].includes(shape)){
@@ -153,15 +161,15 @@ start:disabled?disabledGradientStart:gradientStart,
153161
end:disabled?disabledGradientEnd:gradientEnd,
154162
colors:backgroundColors,
155163
collapsable:false,
156-
style:[styles.button,shapeStyle,buttonStyle],__source:{fileName:_jsxFileName,lineNumber:151}},
164+
style:[styles.button,shapeStyle,buttonStyle,disabledStyle],__source:{fileName:_jsxFileName,lineNumber:159}},
157165

158166
this.renderButton({textStyle:styles.text}));
159167

160168

161169
}else{
162170
var border=type==='border'&&styles.border;
163171
content=
164-
_react2.default.createElement(_reactNative.View,{style:[styles.button,border,shapeStyle,buttonStyle],__source:{fileName:_jsxFileName,lineNumber:164}},
172+
_react2.default.createElement(_reactNative.View,{style:[styles.button,border,shapeStyle,buttonStyle,disabledStyle],__source:{fileName:_jsxFileName,lineNumber:172}},
165173
this.renderButton({textStyle:styles.secondaryText}));
166174

167175

@@ -177,10 +185,9 @@ style:[
177185
styles.container,
178186
{
179187
width:buttonWidth,
180-
height:buttonHeight,
181-
opacity:disabled?disabledOpacity:1},
188+
height:buttonHeight},
182189

183-
style],__source:{fileName:_jsxFileName,lineNumber:171}},
190+
style],__source:{fileName:_jsxFileName,lineNumber:179}},
184191

185192

186193
content));

src/ButtonComponent.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,13 @@ class ButtonComponent extends Component {
6161
shouldComponentUpdate(nextProps) {
6262
if (this.props.image !== nextProps.image) return true;
6363
if (this.props.text !== nextProps.text) return true;
64+
if (this.props.disabled !== nextProps.disabled) return true;
6465
if (this.props.states && this.props.buttonState !== nextProps.buttonState) return true;
6566
if (this.props.states && this.props.states[this.props.buttonState].progressFill) return true;
67+
if (
68+
this.props.states &&
69+
this.props.states[this.props.buttonState].disabled !== nextProps.states[nextProps.buttonState].disabled
70+
) return true;
6671
return false;
6772
}
6873

@@ -137,6 +142,9 @@ class ButtonComponent extends Component {
137142
const buttonStyle = this.getProp('buttonStyle');
138143
const shape = this.getProp('shape');
139144
const onPress = this.getProp('onPress');
145+
const disabledStyle = disabled
146+
? { opacity: disabledOpacity }
147+
: null;
140148

141149
let shapeStyle;
142150
if (['round', 'circle'].includes(shape)) {
@@ -153,15 +161,15 @@ class ButtonComponent extends Component {
153161
end={disabled ? disabledGradientEnd : gradientEnd}
154162
colors={backgroundColors}
155163
collapsable={false}
156-
style={[styles.button, shapeStyle, buttonStyle]}
164+
style={[styles.button, shapeStyle, buttonStyle, disabledStyle]}
157165
>
158166
{this.renderButton({ textStyle: styles.text })}
159167
</LinearGradient>
160168
);
161169
} else {
162170
const border = type === 'border' && styles.border;
163171
content = (
164-
<View style={[styles.button, border, shapeStyle, buttonStyle]}>
172+
<View style={[styles.button, border, shapeStyle, buttonStyle, disabledStyle]}>
165173
{this.renderButton({ textStyle: styles.secondaryText })}
166174
</View>
167175
);
@@ -178,7 +186,6 @@ class ButtonComponent extends Component {
178186
{
179187
width: buttonWidth,
180188
height: buttonHeight,
181-
opacity: disabled ? disabledOpacity : 1,
182189
},
183190
style,
184191
]}

0 commit comments

Comments
 (0)