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
 
15
 
16
     @Override
16
     @Override
17
     protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
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
 
37
 
38
   render() {
38
   render() {
39
     return (
39
     return (
40
-      <View style={styles.container} key={'guyguy'}>
40
+      <View style={styles.container}>
41
         <View style={styles.button}>
41
         <View style={styles.button}>
42
           <TouchableOpacity onPress={() => Alert.alert(this.props.title, 'Thanks for that :)')}>
42
           <TouchableOpacity onPress={() => Alert.alert(this.props.title, 'Thanks for that :)')}>
43
             <Text style={styles.text}>{this.props.title}</Text>
43
             <Text style={styles.text}>{this.props.title}</Text>