Do you think IIT Guwahati certified course can help you in your career?
No
Introduction
Suppose you are a developer. Sometimes you have to deal with web development or simply HTML and CSS. In that case, you must have faced difficulty arranging the layouts and positions of elements.
In some scenarios, if you want to arrange all the elements towards the left, center, or right, you have to do it individually for every element. So is there any better way to efficiently handle the layout and positioning of elements?
The answer is Yes. We can achieve our goal quickly with the help of flex and using its different properties to adjust elements' position. We will learn about different positions in flex while moving further in the blog, so let’s get on with our topic without wasting any further time.
Flex is a property that decides the positioning of elements within a container’s main and cross-axis. We can select the flex property in CSS, but it is selected by default in react native. In react, flex makes the component flexible according to the flex value.
We have already explained everything about flexbox and layout in react native with scratch to a higher level with proper examples. There we have explained all the properties in detail. So If you have any doubt about the properties of flex, it is advised that you must go through thisblog first. After understanding that blog, there is a meagre chance of any doubt. In this blog, we will discuss various examples using different flex properties to set different positions of elements.
In this blog, the section will see various examples of different positions of elements in the display.
Example 1
In this example, we will place the text input and button right to each other. To do so, set the flexDirection: row and flex: 1. Flex:1 means the inner components will occupy the total height from top to bottom, and the flexDirection: row will arrange the items in row order.
In this example, we will place the textInput and button in a normal flex axis with flex-direction specified as the column. This will occupy the full space of the device.
This example will set the inner view width as 100% and remove the flex property. After removing the flex from inside, now textInput and button will lie alongside each other, and their heights will be set to default.
React Js is used for making responsive web applications, whereas we use react native when we want to create a mobile application with a native feel.
What does flexDirection specify in flex?
It specifies the direction in which elements are aligned, either horizontally or vertically.
Mention some of the advantages of react-native.
It has a very large community, we can also reuse the code that is written once, and with this, we also have some additional plugins.
Are there any default props available in react native?
Yes, they are present in react native and can be used when we do not pass the prop value, then it can use them.
Conclusion
In this article, we have extensively discussed different positions in flex in react native with a proper introduction followed by good examples of different properties with code and output.
We hope this blog has helped you enhance your knowledge of flex in react native.
And if you want to learn more about flexbox and its properties, you must refer to thisblog. You will understand every property of flex with explanation and with examples.