To achieve the desired layout, flexbox offers three main properties − flexDirection justifyContent and alignItems.
The following table shows the possible options:
Property | Values | Description |
---|---|---|
flexDirection | ‘column,' 'row’ | Used to specify if elements will be aligned vertically or horizontally. |
justifyContent | 'center', 'flex-start', 'flex-end', 'space-around', 'space-between' | Used to determine how elements should be distributed inside the container. |
alignItems | 'center', 'flex-start', 'flex-end', 'stretched' | Used to determine how should elements be distributed inside the container along the secondary axis (opposite of flexDirection) |
A component can specify the layout of its children using the Flexbox algorithm. Flexbox is designed to provide a consistent layout on different screen sizes. Usually, use a combination of flexDirection, alignItems, and justifyContent to achieve a suitable layout.
Flexbox works the same way in React Native as in CSS on the web, with a few exceptions. The defaults are different, with flexDirection defaulting to column instead of row, alignContent defaulting to flex-start instead of stretch, flexShrink defaulting to 0 instead of 1, the flex parameter only supporting a single number.
A component can specify the layout of its children using the Flexbox algorithm. Flexbox is designed to provide a consistent layout on different screen sizes.
flexDirection controls the direction in which the children of a node are laid out. This is also referred to as the central axis. The cross axis is perpendicular to the central axis, or the axis in which the wrapping lines are laid out.
Layout direction specifies the direction in which children and text in a hierarchy should be laid out. Layout direction also affects what edge start and end refer to. By default, React Native lays out with LTR layout direction. In this mode, start refers to left, and end refers to right.
The position type of an element defines how it is positioned within its parent.
|