Generally in the excel sheet..we have rows like below
Row1
Row2
Row3
and columns like
column1 | column2 | column3
But why in react native when using flexDirection: 'column'
the box's/text are defined as
flexcolumn1
flexcolumn2
flexcolumn3
and when using flexDirection: 'row'
the box's/text are defined as
flexrow1 | flexrow2 | flexrow3
i find this weird and getting confused... is this just standard difference in react native or there is different concept behind this ?
Flex Direction By default, React Native lays out with LTR layout direction. In this mode start refers to left and end refers to right. LTR (default value) Text and children are laid out from left to right. Margin and padding applied to the start of an element are applied on the left side.
To achieve the desired layout, flexbox offers three main properties − flexDirection justifyContent and alignItems. The following table shows the possible options. Used to specify if elements will be aligned vertically or horizontally.
Normally you will use flex: 1 , which tells a component to fill all available space, shared evenly amongst other components with the same parent. The larger the flex given, the higher the ratio of space a component will take compared to its siblings.
js import React from "react"; import { StyleSheet, View, Text } from "react-native"; export default function App() { return <View style={styles. container}></View>; } const styles = StyleSheet. create({ container: { flex: 1, backgroundColor: "#7CA1B4", alignItems: "center", justifyContent: "center", }, });
I think you're correct to point out that rows are stacked on top of one another:
Row 1
Row 2
Row 3
And that columns are set side by side:
Column 1 | Column 2 | Column 3
The thing to understand here is what flexDirection
means. We set it on a container. If we set it to row
, we're not saying that each child of the container is it's own row. If we were you'd be right to say that things should be laid out like this:
Row 1
Row 2
Row 3
We're saying that the container itself is going to be a row, and children within the container are going to be elements in the row:
Row 1 Item 1 | Row 1 Item 2 | Row 1 Item 3
Here's how the docs word it:
flexDirection controls the direction in which the children of a node are laid out. This is also referred to as the main axis.
It doesn't say that it sets whether the children of a node are rows/columns themselves, it's saying what direction that they will flow. Maybe horizontal
and vertical
would have been better names.
I think it is meant like this:
column1_cell1
column1_cell2
column1_cell3
row1_cell1, row1_cell2, row1_cell3
In the first example all the "flex cells" are in one column, in the other they are all in one row.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With