Reputation: 525
If say the grid around the < button and the Modes text represents a flexbox row, how do you style the items such that the text is always central and the button is always at the start of the row?
i.e. should they be two seperate views with flex=1 or is there a way to put something on top of a row without impacting the centering of the text?
Upvotes: 0
Views: 25
Reputation: 1737
You can do this with flexbox
<View style={{flexDirection: 'row', alignItems: 'center', backgroundColor: 'steelblue', height: 40, padding: 16}}>
<View style={{flex: 0.1}}>
<TouchableOpacity onPress={() => _navigate(props, 'Home')}>
<Icons icon="Ionicons" name="chevron-back" size={24} color={theme.colors.text} />
</TouchableOpacity>
</View>
<View style={{flex: 0.8}}>
<Text style={{textAlign: 'center'}}>Centered Text</Text>
</View>
<View style={{flex: 0.1}}/>
</View>
Upvotes: 0
Reputation: 3093
I had a similar issue a few months ago. I used one trick, define a fake view at the end of the row with the same width as the button has and MODES
text will be in the centre.
<View style={{ flexDirection: 'row', justifyContent: 'space-between' }}>
<Button style={{ width: 30, height: 30 }} />
<Text>MODES</Text>
<View style={{ width: 30 }} />
</View>
Upvotes: 2