Browse Source

Measure TopBar buttons using using MeasureSpec.UNSPECIFIED

This change lets buttons stretch horizontally using padding and
margins and not only by changing width property explicitly.
Guy Carmeli 5 years ago
parent
commit
dd93c5147a

+ 1
- 4
lib/android/app/src/main/java/com/reactnativenavigation/views/titlebar/TitleBarReactButtonView.java View File

@@ -15,9 +15,6 @@ public class TitleBarReactButtonView extends ReactView {
15 15
 
16 16
     @Override
17 17
     protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
18
-        super.onMeasure(
19
-                getChildCount() > 0 ? MeasureSpec.makeMeasureSpec(getChildAt(0).getWidth(), MeasureSpec.EXACTLY) : widthMeasureSpec,
20
-                heightMeasureSpec
21
-        );
18
+        super.onMeasure(MeasureSpec.makeMeasureSpec(MeasureSpec.getSize(widthMeasureSpec), MeasureSpec.UNSPECIFIED), heightMeasureSpec);
22 19
     }
23 20
 }

+ 1
- 1
playground/src/screens/CustomRoundedButton.js View File

@@ -37,7 +37,7 @@ class CustomRoundedButton extends Component {
37 37
 
38 38
   render() {
39 39
     return (
40
-      <View style={styles.container} key={'guyguy'}>
40
+      <View style={styles.container}>
41 41
         <View style={styles.button}>
42 42
           <TouchableOpacity onPress={() => Alert.alert(this.props.title, 'Thanks for that :)')}>
43 43
             <Text style={styles.text}>{this.props.title}</Text>