Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

react native flex direction

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 ?

like image 754
AutoMEta Avatar asked Apr 12 '17 08:04

AutoMEta


People also ask

How do you give a flex direction in React Native?

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.

How many flex directions are there in Flex React Native?

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.

What does flex 1 mean React Native?

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.

How do I set display flex in React Native?

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", }, });


2 Answers

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.

like image 108
Adam Zerner Avatar answered Nov 15 '22 08:11

Adam Zerner


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.

like image 37
Viktor Sec Avatar answered Nov 15 '22 08:11

Viktor Sec