Image for post
Image for post
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'
}
})
Image for post
Image for post
Initial View

Styling the Container

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

Overriding the Container Style

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

Thanks for Reading!

React Native Coach

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

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store