The struggle is real

Understanding Flexbox in React Native

Mastering these simple Flexbox recipes will make you a React Native UI master in no time

Getting Started

//Our views<View style={styles.container}>
<View style={styles.viewStyleOne}>
<Text style={styles.textStyle}> 1 </Text>
</View>
<View style={styles.viewStyleTwo}>
<Text style={styles.textStyle}> 2 </Text>
</View>
<View style={styles.viewStyleThree}>
<Text style={styles.textStyle}> 3 </Text>
</View>
</View>//Styleslet styles = StyleSheet.create({
container: { backgroundColor:'#4286f4'},
viewStyleOne: {
width:40,
height:40,
justifyContent: 'center',
alignItems:'center',
backgroundColor:'#b642f4'
},
textStyle:{
textAlign:'center'
}
})
Initial View

Styling the Container

container: { 
backgroundColor:'#4286f4',
flex: 1
}
flex : 1
container: { 
backgroundColor:'#4286f4',
flex: 1,
flexDirection:'row'
}
flexDirection set to ‘row’
container:{ 
backgroundColor:'#4286f4',
flex: 1,
flexDirection: 'row',
justifyContent: 'flex-end',
alignItems:'flex-start'
}
justifyContent: ‘flex-end’
container: { 
backgroundColor:'#4286f4',
flex: 1,
flexDirection: 'row',
justifyContent: 'flex-end',
alignItems:'flex-end'
}
alignItems:’flex-end’
justifyContent: 'center',
alignItems:'center'
Items to center
space-around
space-between

Overriding the Container Style

alignSelf: 'flex-start' 
telling the item to align at flex start
flexGrow: 1
flexGrow
flexBasis:50 //firstView style
flexBasis:20 //secondView style
flexBasis:30 //ThirdView style
flexBasis

Thanks for Reading!

React Native Coach

Bringing you the best React Native, GraphQL, Redux, and…

Navdeep Singh Bedi

Written by

Software developer and learner. https://navdroid.github.io/

React Native Coach

Bringing you the best React Native, GraphQL, Redux, and Mobile Design resources from around the web. To submit stories for review or for inquiries about sponsorship: [email protected].

Navdeep Singh Bedi

Written by

Software developer and learner. https://navdroid.github.io/

React Native Coach

Bringing you the best React Native, GraphQL, Redux, and Mobile Design resources from around the web. To submit stories for review or for inquiries about sponsorship: [email protected].