SlideShare a Scribd company logo
Understanding
Flexbox
Layout in
React Native
https://www.bacancytechnology.com/
Introduction
If you have worked with mobile
applications development or frontend
development, you might be familiar with
designing an application using flexbox. If
you don’t know, then don’t worry. Just stick
to this tutorial till the end; you will come to
know the basics and implementation of
flexbox layout.


Let’s move ahead with our tutorial: Flexbox
Layout in React Native Application without
further ado.
Tutorial Goals
General discussion about flexbox layout
Different React Native layouts
Flexbox layout properties
Implementing flexbox layout in React
Native app
The first thing to know is what our tutorial
has for you. So, these are the main sections
that we will cover in this blog post.
So much knowledge, right? Moving towards
our first section. Let’s read about what
flexbox is and learn about its concept.
What is
Flexbox:
Fundamental
Concepts of
Flexbox Layouts
Flexible Box Module, popularly known as
flexbox, is a designing model that deals with
a one-dimensional layout of an application.
Now, what does this one-dimensional
layout means? Simple, it states that the
concept of flexbox relies on the layout with
one dimension at a time – it could be a row
or column.


Further, flexbox gives the freedom to
distribute the space between interface
items and powerful alignments capabilities.
Flexbox layout has made developers’ lives
easy by lessening application
responsiveness struggles.


Fundamental concepts of Flexbox Layout
Two Axes of Flexbox
Main Axis: It is defined by property flex-
direction
Cross Axis: It runs perpendicular to the
main axis
Flexbox deals with two axes –




Start and End Lines
Before, CSS had given more importance to
left-to-write writing mode and made it
default. But, with modern layout methods, a
wide range of writing modes was
introduced. Thus, it stopped the assumption
of text lines starting at the top left of the
document and ending at the right of the
document.
Flex Container
The area of the document on which we want
to apply the flex property can be said as a
flex container. To create a flex container,
you just need to set the display property(of
the area’s container) as flex or inline-flex.
And, items within the area’s container will
become flex items.
Looking for React Native
developers to build high-
performance mobile
applications?
Bacancy has the most
dedicated and skilled
developers. Contact us
today and hire React Native
developer!
React Native
Layout
Differences
React Native provides limited but sufficient
flexbox layout properties and values. The
main difference is that all the React Native
container elements are, by default, Flex
containers. There’s no need to add a display:
‘flex’. It avoids writing extra code.


Keep in mind that the child element of the
parent container can be positioned with the
property Flex item – ‘align-self’. Here’s an
example of applying the property align-
self:flex-end to Flex container (last box) that
contains child elements.
Here are different defaults for React native
development that makes flexbox more
advantageous.
Properties:
Flexbox Layout
in React Native
This section will discuss flexbox properties
that can enhance your application’s design.
Flexbox Layout
in React Native
Example
orange box
white box
green box.
Let’s implement flexbox in our React Native
application.
Our demo application will have a parent
container with three boxes:


The parent and child container is a View
Component.
// Layout const App = () => { return (
<View style={styles.container}>
<View style={styles.orangeBox} />
<View style={styles.whiteBox} />
<View style={styles.greenBox} />
</View> ); }; // Style const styles =
StyleSheet.create({ container: {
backgroundColor: '#454545', },
orangeBox: { width: 80, height: 80,
backgroundColor: 'orange', }, whiteBox: {
width: 80, height: 80, backgroundColor:
'white', }, greenBox: { width: 80, height: 80,
backgroundColor: 'blue', }, });
Output
After adding the property is flex: 1, the
space is split into a single group; thus, our
parent container will display on the entire
screen.




container: {
flex: 1,
backgroundColor: '#454545',
},
React Native Flex
Output
React Native Flex Direction
flexDirection controls the direction of child
elements of the parent container. Here are
the values you can add to flexDirection.
column– It is the default value. It aligns
child elements from top to bottom. On
enabling the wrapping, the next line will
start to the right of the first item to the
top container.
row– It aligns the elements from left to
the right. The next line will start under
the first element to the left container on
enabling the wrapping.
column- reverse– It aligns elements in
the reverse order – bottom to top. On
enabling the wrapping, the next line will
start to the right of the first item to the
bottom container.
row-reverse– It aligns elements in the
reverse order – right to left. The next
line will start under the first item to the
right container to enable the wrapping.
container: {
flex: 1,
flexDirection: 'row',
backgroundColor: '#454545',
},
Output
React Native Justify
Content
flex-start- It is the default value. Aligns
elements to the container’s main axis
start.
flex-end-Aligns elements to the
container’s main axis end.
center- Aligns elements to the
container’s main axis center.
justifyContent is used to align the child
elements within the main axis of the parent
container. You can set the elements
horizontally and vertically by setting
flexDirection as row and column.


The property offers a few more values are
stated below:
space-between- Evenly space off the
elements and distribute the remaining
spaces equally between the children
across the container’s main axis.
space-around- Evenly space off the
elements and distribute the remaining
spaces around the children across the
container’s main axis.
space-evenly- Evenly distributes the
elements. The spaces between the
adjacent items, first item and main-
start edge, and last item and main-end
edge are the same.
Let’s see a few examples.
justifyContent: ‘flex-start’


container: {
flex: 1,
flexDirection: 'row',
justifyContent: 'flex-
start',
backgroundColor:
'#454545',
},
Output
Below are the screenshots of the output of
each of these values used for property
justifyContent.


justifyContent: ‘flex-end’
justifyContent: ‘center’


justifyContent: ‘space-around’
justifyContent: ‘space-between’


justifyContent: ‘space-evenly’
React Native Align Items


alignItems is used to align the child with the
cross axis of its parent container. Similar to
justifyContent that aligns with the main
axis, this property will align the children
with the cross axis.
Let’s take some examples.


alignItems: ‘flex-start’
container: {
flex: 1,
flexDirection: 'row',
justifyContent: flex-start',
alignItems: flex-start,
backgroundColor: '#454545',
},
Output
Below are the screenshots of each of these
values.
alignItems: ‘flex-end’
alignItems: ‘center’


So, this was understanding and
implementing the Flexbox layout in React
Native. I hope the purpose of the tutorial
was served as you expected.
Github
Repository:
Flexbox React
Native Example
If you wish to clone the repository and play
around with the code. Here’s the github
repo: flexbox-layout-demo.


If you want to practice more with an online
game interface, then you can play the game
flexbox froggy.
Conclusion
Flexbox is easy to maintain and understand;
once you have understood its concept, you
would love to work with it. If you have any
queries, suggestions, or feedback, write us
back. Also, feel free to suggest topics if you
want us to write a tutorial on them. Keep
learning!
Thank You
https://www.bacancytechnology.com/

More Related Content

PDF
Jetpack compose
LutasLin
 
PDF
Svelte the future of frontend development
twilson63
 
PPTX
Angular 9
Raja Vishnu
 
PDF
Jetpack Compose beginner.pdf
AayushmaAgrawal
 
PPTX
How native is React Native? | React Native vs Native App Development
Devathon
 
PPTX
React.js - The Dawn of Virtual DOM
Jimit Shah
 
PDF
React and redux
Mystic Coders, LLC
 
PDF
Introduction to Redux
Ignacio Martín
 
Jetpack compose
LutasLin
 
Svelte the future of frontend development
twilson63
 
Angular 9
Raja Vishnu
 
Jetpack Compose beginner.pdf
AayushmaAgrawal
 
How native is React Native? | React Native vs Native App Development
Devathon
 
React.js - The Dawn of Virtual DOM
Jimit Shah
 
React and redux
Mystic Coders, LLC
 
Introduction to Redux
Ignacio Martín
 

What's hot (20)

PPTX
Les Streams de Java 8
Antoine Rey
 
PDF
Introduction to react native
Dani Akash
 
PPTX
presentation on Integrative Case of Track Software Ltd
Pritom27
 
PDF
Valuation of Tesla
Muhammad Shiddiq Azis
 
PDF
Reactjs Basics
Hamid Ghorbani
 
PPTX
Le Langage CSS
Mohammed Amine Mostefai
 
PDF
ReactJS presentation
Thanh Tuong
 
PDF
Introduction to react-query. A Redux alternative? (Nikos Kleidis, Front End D...
GreeceJS
 
PDF
React Native
vishal kumar
 
PPTX
React-JS.pptx
AnmolPandita7
 
PDF
Jetpack Compose a new way to implement UI on Android
Nelson Glauber Leal
 
PPTX
Introduction à React JS
Abdoulaye Dieng
 
PDF
Angular développer des applications .pdf
imenhamada17
 
PDF
Android-Tp2: liste et adaptateurs
Lilia Sfaxi
 
PPTX
02 - [ASP.NET Core] ASP.NET Core MVC
Cellenza
 
PDF
Why I ❤️ Kotlin Multiplatform (and want YOU to also ❤️ Kotlin Multiplatform)
Derek Lee
 
PPTX
20180518 QNAP Seminar - Introduction to React Native
Eric Deng
 
PDF
初探 Data API Builder:在幾分鐘內將資料庫轉換成 REST 和 GraphQL 不再是夢想
Alan Tsai
 
PPTX
Module 2 introduction à asp.net web forms
Mohammed Amine Mostefai
 
PDF
Declarative UIs with Jetpack Compose
Ramon Ribeiro Rabello
 
Les Streams de Java 8
Antoine Rey
 
Introduction to react native
Dani Akash
 
presentation on Integrative Case of Track Software Ltd
Pritom27
 
Valuation of Tesla
Muhammad Shiddiq Azis
 
Reactjs Basics
Hamid Ghorbani
 
Le Langage CSS
Mohammed Amine Mostefai
 
ReactJS presentation
Thanh Tuong
 
Introduction to react-query. A Redux alternative? (Nikos Kleidis, Front End D...
GreeceJS
 
React Native
vishal kumar
 
React-JS.pptx
AnmolPandita7
 
Jetpack Compose a new way to implement UI on Android
Nelson Glauber Leal
 
Introduction à React JS
Abdoulaye Dieng
 
Angular développer des applications .pdf
imenhamada17
 
Android-Tp2: liste et adaptateurs
Lilia Sfaxi
 
02 - [ASP.NET Core] ASP.NET Core MVC
Cellenza
 
Why I ❤️ Kotlin Multiplatform (and want YOU to also ❤️ Kotlin Multiplatform)
Derek Lee
 
20180518 QNAP Seminar - Introduction to React Native
Eric Deng
 
初探 Data API Builder:在幾分鐘內將資料庫轉換成 REST 和 GraphQL 不再是夢想
Alan Tsai
 
Module 2 introduction à asp.net web forms
Mohammed Amine Mostefai
 
Declarative UIs with Jetpack Compose
Ramon Ribeiro Rabello
 
Ad

Similar to Understanding Flexbox Layout in React Native.pdf (20)

PDF
A complete guide to flexbox
Bytes Technolab Inc.
 
PPTX
Flex box
Harish Karthick
 
PDF
Flexbox Will Shock You!
Scott Vandehey
 
PDF
Putting Flexbox into Practice (Fronteers)
Zoe Gillenwater
 
PDF
Is Flexbox the Future of Layout?
jameswillweb
 
PDF
Putting Flexbox into Practice
Zoe Gillenwater
 
PDF
[React Native] Lecture 4: Basic Elements and UI Layout by using FlexBox
Kobkrit Viriyayudhakorn
 
PDF
Building Layouts with CSS
Boris Paillard
 
PDF
Leveling Up With Flexbox (Smart Web Conference)
Zoe Gillenwater
 
PDF
World of Flexbox
Elad Shechter
 
PPTX
flexbox report
LearningTech
 
PDF
CSS Conf Budapest - New CSS Layout
Rachel Andrew
 
PPTX
Lecture-9.pptx
vishal choudhary
 
PPTX
Understanding the flex layout
Barak Drechsler
 
PDF
Flex Web Development.pdf
SEO expate Bangladesh Ltd
 
PDF
Leveling Up with Flexbox (Smashing Conference)
Zoe Gillenwater
 
PPTX
Beautiful UI in react native By - nativebase.io
Geekyants
 
PPT
React native
Mohammed El Rafie Tarabay
 
PDF
Using Flexbox Today (CSS Summit 2016)
Zoe Gillenwater
 
PDF
Understanding flexbox
mustafa sarac
 
A complete guide to flexbox
Bytes Technolab Inc.
 
Flex box
Harish Karthick
 
Flexbox Will Shock You!
Scott Vandehey
 
Putting Flexbox into Practice (Fronteers)
Zoe Gillenwater
 
Is Flexbox the Future of Layout?
jameswillweb
 
Putting Flexbox into Practice
Zoe Gillenwater
 
[React Native] Lecture 4: Basic Elements and UI Layout by using FlexBox
Kobkrit Viriyayudhakorn
 
Building Layouts with CSS
Boris Paillard
 
Leveling Up With Flexbox (Smart Web Conference)
Zoe Gillenwater
 
World of Flexbox
Elad Shechter
 
flexbox report
LearningTech
 
CSS Conf Budapest - New CSS Layout
Rachel Andrew
 
Lecture-9.pptx
vishal choudhary
 
Understanding the flex layout
Barak Drechsler
 
Flex Web Development.pdf
SEO expate Bangladesh Ltd
 
Leveling Up with Flexbox (Smashing Conference)
Zoe Gillenwater
 
Beautiful UI in react native By - nativebase.io
Geekyants
 
Using Flexbox Today (CSS Summit 2016)
Zoe Gillenwater
 
Understanding flexbox
mustafa sarac
 
Ad

More from Katy Slemon (20)

PDF
React Alternatives Frameworks- Lightweight Javascript Libraries.pdf
Katy Slemon
 
PDF
Data Science Use Cases in Retail & Healthcare Industries.pdf
Katy Slemon
 
PDF
How Much Does It Cost To Hire Golang Developer.pdf
Katy Slemon
 
PDF
What’s New in Flutter 3.pdf
Katy Slemon
 
PDF
Why Use Ruby On Rails.pdf
Katy Slemon
 
PDF
How Much Does It Cost To Hire Full Stack Developer In 2022.pdf
Katy Slemon
 
PDF
How to Implement Middleware Pipeline in VueJS.pdf
Katy Slemon
 
PDF
How to Build Laravel Package Using Composer.pdf
Katy Slemon
 
PDF
Sure Shot Ways To Improve And Scale Your Node js Performance.pdf
Katy Slemon
 
PDF
How to Develop Slack Bot Using Golang.pdf
Katy Slemon
 
PDF
IoT Based Battery Management System in Electric Vehicles.pdf
Katy Slemon
 
PDF
The Ultimate Guide to Laravel Performance Optimization in 2022.pdf
Katy Slemon
 
PDF
New Features in iOS 15 and Swift 5.5.pdf
Katy Slemon
 
PDF
How to Hire & Manage Dedicated Team For Your Next Product Development.pdf
Katy Slemon
 
PDF
Choose the Right Battery Management System for Lithium Ion Batteries.pdf
Katy Slemon
 
PDF
Flutter Performance Tuning Best Practices From the Pros.pdf
Katy Slemon
 
PDF
Angular Universal How to Build Angular SEO Friendly App.pdf
Katy Slemon
 
PDF
How to Set Up and Send Mails Using SendGrid in NodeJs App.pdf
Katy Slemon
 
PDF
Ruby On Rails Performance Tuning Guide.pdf
Katy Slemon
 
PDF
Uncovering 04 Main Types and Benefits of Salesforce ISV Partnerships.pdf
Katy Slemon
 
React Alternatives Frameworks- Lightweight Javascript Libraries.pdf
Katy Slemon
 
Data Science Use Cases in Retail & Healthcare Industries.pdf
Katy Slemon
 
How Much Does It Cost To Hire Golang Developer.pdf
Katy Slemon
 
What’s New in Flutter 3.pdf
Katy Slemon
 
Why Use Ruby On Rails.pdf
Katy Slemon
 
How Much Does It Cost To Hire Full Stack Developer In 2022.pdf
Katy Slemon
 
How to Implement Middleware Pipeline in VueJS.pdf
Katy Slemon
 
How to Build Laravel Package Using Composer.pdf
Katy Slemon
 
Sure Shot Ways To Improve And Scale Your Node js Performance.pdf
Katy Slemon
 
How to Develop Slack Bot Using Golang.pdf
Katy Slemon
 
IoT Based Battery Management System in Electric Vehicles.pdf
Katy Slemon
 
The Ultimate Guide to Laravel Performance Optimization in 2022.pdf
Katy Slemon
 
New Features in iOS 15 and Swift 5.5.pdf
Katy Slemon
 
How to Hire & Manage Dedicated Team For Your Next Product Development.pdf
Katy Slemon
 
Choose the Right Battery Management System for Lithium Ion Batteries.pdf
Katy Slemon
 
Flutter Performance Tuning Best Practices From the Pros.pdf
Katy Slemon
 
Angular Universal How to Build Angular SEO Friendly App.pdf
Katy Slemon
 
How to Set Up and Send Mails Using SendGrid in NodeJs App.pdf
Katy Slemon
 
Ruby On Rails Performance Tuning Guide.pdf
Katy Slemon
 
Uncovering 04 Main Types and Benefits of Salesforce ISV Partnerships.pdf
Katy Slemon
 

Recently uploaded (20)

PDF
SparkLabs Primer on Artificial Intelligence 2025
SparkLabs Group
 
PPTX
C Programming Basics concept krnppt.pptx
Karan Prajapat
 
PDF
Software Development Methodologies in 2025
KodekX
 
PDF
Google’s NotebookLM Unveils Video Overviews
SOFTTECHHUB
 
PPTX
How to Build a Scalable Micro-Investing Platform in 2025 - A Founder’s Guide ...
Third Rock Techkno
 
PDF
CIFDAQ's Token Spotlight: SKY - A Forgotten Giant's Comeback?
CIFDAQ
 
PDF
Doc9.....................................
SofiaCollazos
 
PDF
A Day in the Life of Location Data - Turning Where into How.pdf
Precisely
 
PDF
BLW VOCATIONAL TRAINING SUMMER INTERNSHIP REPORT
codernjn73
 
PPTX
Comunidade Salesforce São Paulo - Desmistificando o Omnistudio (Vlocity)
Francisco Vieira Júnior
 
PDF
Event Presentation Google Cloud Next Extended 2025
minhtrietgect
 
PDF
CIFDAQ's Teaching Thursday: Moving Averages Made Simple
CIFDAQ
 
PDF
Oracle AI Vector Search- Getting Started and what's new in 2025- AIOUG Yatra ...
Sandesh Rao
 
PDF
Presentation about Hardware and Software in Computer
snehamodhawadiya
 
PDF
This slide provides an overview Technology
mineshkharadi333
 
PDF
The Evolution of KM Roles (Presented at Knowledge Summit Dublin 2025)
Enterprise Knowledge
 
PDF
Security features in Dell, HP, and Lenovo PC systems: A research-based compar...
Principled Technologies
 
PDF
Unlocking the Future- AI Agents Meet Oracle Database 23ai - AIOUG Yatra 2025.pdf
Sandesh Rao
 
PDF
Why Your AI & Cybersecurity Hiring Still Misses the Mark in 2025
Virtual Employee Pvt. Ltd.
 
PDF
Cloud-Migration-Best-Practices-A-Practical-Guide-to-AWS-Azure-and-Google-Clou...
Artjoker Software Development Company
 
SparkLabs Primer on Artificial Intelligence 2025
SparkLabs Group
 
C Programming Basics concept krnppt.pptx
Karan Prajapat
 
Software Development Methodologies in 2025
KodekX
 
Google’s NotebookLM Unveils Video Overviews
SOFTTECHHUB
 
How to Build a Scalable Micro-Investing Platform in 2025 - A Founder’s Guide ...
Third Rock Techkno
 
CIFDAQ's Token Spotlight: SKY - A Forgotten Giant's Comeback?
CIFDAQ
 
Doc9.....................................
SofiaCollazos
 
A Day in the Life of Location Data - Turning Where into How.pdf
Precisely
 
BLW VOCATIONAL TRAINING SUMMER INTERNSHIP REPORT
codernjn73
 
Comunidade Salesforce São Paulo - Desmistificando o Omnistudio (Vlocity)
Francisco Vieira Júnior
 
Event Presentation Google Cloud Next Extended 2025
minhtrietgect
 
CIFDAQ's Teaching Thursday: Moving Averages Made Simple
CIFDAQ
 
Oracle AI Vector Search- Getting Started and what's new in 2025- AIOUG Yatra ...
Sandesh Rao
 
Presentation about Hardware and Software in Computer
snehamodhawadiya
 
This slide provides an overview Technology
mineshkharadi333
 
The Evolution of KM Roles (Presented at Knowledge Summit Dublin 2025)
Enterprise Knowledge
 
Security features in Dell, HP, and Lenovo PC systems: A research-based compar...
Principled Technologies
 
Unlocking the Future- AI Agents Meet Oracle Database 23ai - AIOUG Yatra 2025.pdf
Sandesh Rao
 
Why Your AI & Cybersecurity Hiring Still Misses the Mark in 2025
Virtual Employee Pvt. Ltd.
 
Cloud-Migration-Best-Practices-A-Practical-Guide-to-AWS-Azure-and-Google-Clou...
Artjoker Software Development Company
 

Understanding Flexbox Layout in React Native.pdf

  • 3. If you have worked with mobile applications development or frontend development, you might be familiar with designing an application using flexbox. If you don’t know, then don’t worry. Just stick to this tutorial till the end; you will come to know the basics and implementation of flexbox layout. Let’s move ahead with our tutorial: Flexbox Layout in React Native Application without further ado.
  • 5. General discussion about flexbox layout Different React Native layouts Flexbox layout properties Implementing flexbox layout in React Native app The first thing to know is what our tutorial has for you. So, these are the main sections that we will cover in this blog post. So much knowledge, right? Moving towards our first section. Let’s read about what flexbox is and learn about its concept.
  • 7. Flexible Box Module, popularly known as flexbox, is a designing model that deals with a one-dimensional layout of an application. Now, what does this one-dimensional layout means? Simple, it states that the concept of flexbox relies on the layout with one dimension at a time – it could be a row or column. Further, flexbox gives the freedom to distribute the space between interface items and powerful alignments capabilities. Flexbox layout has made developers’ lives easy by lessening application responsiveness struggles. Fundamental concepts of Flexbox Layout
  • 8. Two Axes of Flexbox Main Axis: It is defined by property flex- direction Cross Axis: It runs perpendicular to the main axis Flexbox deals with two axes – Start and End Lines Before, CSS had given more importance to left-to-write writing mode and made it default. But, with modern layout methods, a wide range of writing modes was introduced. Thus, it stopped the assumption of text lines starting at the top left of the document and ending at the right of the document.
  • 9. Flex Container The area of the document on which we want to apply the flex property can be said as a flex container. To create a flex container, you just need to set the display property(of the area’s container) as flex or inline-flex. And, items within the area’s container will become flex items.
  • 10. Looking for React Native developers to build high- performance mobile applications? Bacancy has the most dedicated and skilled developers. Contact us today and hire React Native developer!
  • 12. React Native provides limited but sufficient flexbox layout properties and values. The main difference is that all the React Native container elements are, by default, Flex containers. There’s no need to add a display: ‘flex’. It avoids writing extra code. Keep in mind that the child element of the parent container can be positioned with the property Flex item – ‘align-self’. Here’s an example of applying the property align- self:flex-end to Flex container (last box) that contains child elements.
  • 13. Here are different defaults for React native development that makes flexbox more advantageous.
  • 15. This section will discuss flexbox properties that can enhance your application’s design.
  • 16. Flexbox Layout in React Native Example
  • 17. orange box white box green box. Let’s implement flexbox in our React Native application. Our demo application will have a parent container with three boxes: The parent and child container is a View Component.
  • 18. // Layout const App = () => { return ( <View style={styles.container}> <View style={styles.orangeBox} /> <View style={styles.whiteBox} /> <View style={styles.greenBox} /> </View> ); }; // Style const styles = StyleSheet.create({ container: { backgroundColor: '#454545', }, orangeBox: { width: 80, height: 80, backgroundColor: 'orange', }, whiteBox: { width: 80, height: 80, backgroundColor: 'white', }, greenBox: { width: 80, height: 80, backgroundColor: 'blue', }, }); Output
  • 19. After adding the property is flex: 1, the space is split into a single group; thus, our parent container will display on the entire screen. container: { flex: 1, backgroundColor: '#454545', }, React Native Flex
  • 21. React Native Flex Direction flexDirection controls the direction of child elements of the parent container. Here are the values you can add to flexDirection. column– It is the default value. It aligns child elements from top to bottom. On enabling the wrapping, the next line will start to the right of the first item to the top container. row– It aligns the elements from left to the right. The next line will start under the first element to the left container on enabling the wrapping. column- reverse– It aligns elements in the reverse order – bottom to top. On enabling the wrapping, the next line will start to the right of the first item to the bottom container.
  • 22. row-reverse– It aligns elements in the reverse order – right to left. The next line will start under the first item to the right container to enable the wrapping. container: { flex: 1, flexDirection: 'row', backgroundColor: '#454545', }, Output
  • 23. React Native Justify Content flex-start- It is the default value. Aligns elements to the container’s main axis start. flex-end-Aligns elements to the container’s main axis end. center- Aligns elements to the container’s main axis center. justifyContent is used to align the child elements within the main axis of the parent container. You can set the elements horizontally and vertically by setting flexDirection as row and column. The property offers a few more values are stated below:
  • 24. space-between- Evenly space off the elements and distribute the remaining spaces equally between the children across the container’s main axis. space-around- Evenly space off the elements and distribute the remaining spaces around the children across the container’s main axis. space-evenly- Evenly distributes the elements. The spaces between the adjacent items, first item and main- start edge, and last item and main-end edge are the same. Let’s see a few examples.
  • 25. justifyContent: ‘flex-start’ container: { flex: 1, flexDirection: 'row', justifyContent: 'flex- start', backgroundColor: '#454545', }, Output
  • 26. Below are the screenshots of the output of each of these values used for property justifyContent. justifyContent: ‘flex-end’
  • 29. React Native Align Items alignItems is used to align the child with the cross axis of its parent container. Similar to justifyContent that aligns with the main axis, this property will align the children with the cross axis. Let’s take some examples. alignItems: ‘flex-start’ container: { flex: 1, flexDirection: 'row', justifyContent: flex-start', alignItems: flex-start, backgroundColor: '#454545', },
  • 30. Output Below are the screenshots of each of these values. alignItems: ‘flex-end’
  • 31. alignItems: ‘center’ So, this was understanding and implementing the Flexbox layout in React Native. I hope the purpose of the tutorial was served as you expected.
  • 33. If you wish to clone the repository and play around with the code. Here’s the github repo: flexbox-layout-demo. If you want to practice more with an online game interface, then you can play the game flexbox froggy.
  • 35. Flexbox is easy to maintain and understand; once you have understood its concept, you would love to work with it. If you have any queries, suggestions, or feedback, write us back. Also, feel free to suggest topics if you want us to write a tutorial on them. Keep learning!