Skip to content

Commit 44c2bda

Browse files
committed
added onLayout prop support
1 parent 3a2437b commit 44c2bda

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

Button.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export default class Button extends Component {
3434
onPress: NOOP,
3535
onPressIn: NOOP,
3636
onPressOut: NOOP,
37+
onLayout: NOOP,
3738
}
3839

3940
static PropTypes = {
@@ -48,6 +49,7 @@ export default class Button extends Component {
4849
onPressIn: PropTypes.func,
4950
onPressOut: PropTypes.func,
5051
onPress: PropTypes.func,
52+
onLayout: PropTypes.func,
5153
disabled: PropTypes.bool,
5254
isLoading: PropTypes.bool,
5355
loadingComponent: PropTypes.element,
@@ -80,6 +82,7 @@ export default class Button extends Component {
8082
touchableProps.underlayColor = this.props.underlayColor
8183
return (
8284
<TouchableHighlight
85+
onLayout={this.props.onLayout}
8386
disabled={this.props.disabled || this.props.isLoading}
8487
style={[this.props.style, this.props.disabled ? this.props.disabledStyle : null,]}
8588
{...touchableProps}
@@ -91,7 +94,9 @@ export default class Button extends Component {
9194
case 'opacityContent':
9295
touchableProps.activeOpacity = this.props.activeOpacity
9396
return (
94-
<View style={[this.props.style, this.props.disabled ? this.props.disabledStyle : null,]}>
97+
<View
98+
onLayout={this.props.onLayout}
99+
style={[this.props.style, this.props.disabled ? this.props.disabledStyle : null,]}>
95100
<TouchableOpacity
96101
disabled={this.props.disabled || this.props.isLoading}
97102
style={[styles.touchContainer]}
@@ -107,8 +112,9 @@ export default class Button extends Component {
107112
touchableProps.onPressIn = this._onBlurPressIn
108113
touchableProps.onPressOut = this._onBlurPressOut
109114
return (
110-
<View onLayout={this._onButtonLayout}
111-
style={[this.props.style, this.props.disabled ? this.props.disabledStyle : null, {position: 'relative', overflow: 'hidden',}]}>
115+
<View
116+
onLayout={this._onButtonLayout}
117+
style={[ {position: 'relative', overflow: 'hidden',}, this.props.style, this.props.disabled ? this.props.disabledStyle : null, ]}>
112118
<TouchableOpacity
113119
disabled={this.props.disabled || this.props.isLoading}
114120
style={styles.touchContainer}
@@ -125,6 +131,7 @@ export default class Button extends Component {
125131
touchableProps.activeOpacity = this.props.activeOpacity
126132
return (
127133
<TouchableOpacity
134+
onLayout={this.props.onLayout}
128135
disabled={this.props.disabled || this.props.isLoading}
129136
style={[this.props.style, this.props.disabled ? this.props.disabledStyle : null, ]}
130137
{...touchableProps}
@@ -181,21 +188,22 @@ export default class Button extends Component {
181188
this.setState({
182189
pressIn: true,
183190
})
184-
this.props.onPressIn.call(this, e)
191+
this.props.onPressIn(e)
185192
}
186193

187194
_onBlurPressOut = (e) => {
188195
this.setState({
189196
pressIn: false,
190197
})
191-
this.props.onPressOut.call(this, e)
198+
this.props.onPressOut(e)
192199
}
193200

194201
_onButtonLayout = (e) => {
195202
this._boxDimension = {
196203
width: e.nativeEvent.layout.width,
197204
height: e.nativeEvent.layout.height,
198205
}
206+
this.props.onLayout(e)
199207
}
200208

201209
//_onTextLayout = (e) => {

0 commit comments

Comments
 (0)