Reputation: 9891
I want to make button in react native with dynamic width. I just want to supply text in button component it create button according to text width.
Upvotes: 1
Views: 3614
Reputation: 9891
<View style={{justifyContent: 'center', alignItems: 'center'}}>
<TouchableHighlight style={{backgroundColor:'red', paddingTop:10, paddingLeft:20, paddingRight:20, paddingBottom:10}}>
<Text style={{color:'white', fontWeight:'bold'}}>BUTTON 2</Text>
</TouchableHighlight>
</View>
Upvotes: 2
Reputation: 53681
To accomplish this, use padding. I've set up an example here.
<TouchableHighlight style={{backgroundColor:'red', paddingTop:10, paddingLeft:20, paddingRight:20, paddingBottom:10}}>
<Text style={{color:'white', fontWeight:'bold'}}>BUTTON 2</Text>
</TouchableHighlight>
https://rnplay.org/apps/Hwinnw
Upvotes: 1