2

I am starting learning react-native-paper, i am not sure how to fix button width, currently it fills whole parent container.

    <View>
        <Button 
        icon="camera" 
        mode="contained" 
        onPress={() => console.log('Pressed')}
        contentStyle={styles.btn}
        >
            Press me
        </Button>
    </View>



const styles = StyleSheet.create({
    btn: {
        width: 30
    }
})

This is not working and button is still full width. Need some help.

raju
  • 6,448
  • 24
  • 80
  • 163

2 Answers2

2

You can change the width of Button directly using style props and adding width to it.

<Button 
   icon="camera" 
   mode="contained" 
   onPress={() => console.log('Pressed')}
   style={{ width: 100 }}
>
  Press me
</Button>

Ferin Patel
  • 3,424
  • 2
  • 17
  • 49
0

If your View tag is a container for the button, the button needs its own View tag with the styles prop called there.

    <View>
      <View style={styles.btn}>
       <Button 
          icon="camera" 
          mode="contained" 
          onPress={() => console.log('Pressed')}
       >
        Press me
       </Button>
      </View>
    </View>



    const styles = StyleSheet.create({
      btn: {
        width: 30
      },
    });
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Dec 01 '21 at 08:56