I'm working my way through the wonderful ReactNativeKatas to learn flexbox layouts in React Native. In the example below, the flex
property on the two child views of the parent View
(the one using the styles.container
) is set to 0.1
. Setting both to 0.1
places the first View
on the absolute left of the display and the second View
in the middle. Why does setting 0.1
to the flex
property of both View
s align them this way?
const FlexSize= (props)=>{
return (
<View style={styles.container}>
<View style={{flex: 0.1}}>
<Box style={{flex: 0.7}}/>
<Box style={{backgroundColor:'yellow'}}/>
<Box/>
<Box style={{flex: 0.3, backgroundColor:'yellow'}}/>
</View>
<View style={{flex: 0.1}}>
<Box style={{flex: 0.5}}/>
<Box style={{backgroundColor:'yellow'}}/>
<Box/>
<Box style={{flex: 0.5, backgroundColor:'yellow'}}/>
</View>
</View>
)
}
const styles = StyleSheet.create({
container: {
flex:1,
flexDirection:'row',
backgroundColor: colors[1],
},
});
Rendered in the simulator: