Skip to content

Commit

Permalink
Measure TopBar buttons using using MeasureSpec.UNSPECIFIED
Browse files Browse the repository at this point in the history
This change lets buttons stretch horizontally using padding and
margins and not only by changing width property explicitly.
  • Loading branch information
guyca committed Dec 25, 2018
1 parent 43ae659 commit dd93c51
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ public TitleBarReactButtonView(Context context, ReactInstanceManager reactInstan

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(
getChildCount() > 0 ? MeasureSpec.makeMeasureSpec(getChildAt(0).getWidth(), MeasureSpec.EXACTLY) : widthMeasureSpec,
heightMeasureSpec
);
super.onMeasure(MeasureSpec.makeMeasureSpec(MeasureSpec.getSize(widthMeasureSpec), MeasureSpec.UNSPECIFIED), heightMeasureSpec);
}
}
2 changes: 1 addition & 1 deletion playground/src/screens/CustomRoundedButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class CustomRoundedButton extends Component {

render() {
return (
<View style={styles.container} key={'guyguy'}>
<View style={styles.container}>
<View style={styles.button}>
<TouchableOpacity onPress={() => Alert.alert(this.props.title, 'Thanks for that :)')}>
<Text style={styles.text}>{this.props.title}</Text>
Expand Down

0 comments on commit dd93c51

Please sign in to comment.