Víctor Yoalli

React Native Flexbox Cheat Sheet

1. Flex Direction (flexDirection)

ValueDescription
rowItems are laid out in a line from left to right.
row-reverseItems are laid out from right to left.
columnItems are laid out from top to bottom.
column-reverseItems are laid out from bottom to top.

Example

jsx
<View style={{ flexDirection: 'row' }}>
  <Text>Item 1</Text>
  <Text>Item 2</Text>
</View>

2. 2. Justify Content (justifyContent)

ValueDescription
flex-startItems align to the start of the container.
flex-endItems align to the end of the container.
centerItems align at the center of the container.
space-betweenItems display with equal spacing between them.
space-aroundItems display with equal spacing around them.
space-evenlyItems display with equal spacing around and between them.

Example

jsx
<View style={{ justifyContent: 'center' }}>
  <Text>Centered Item</Text>
</View>

3. Align Items (alignItems)

ValueDescription
flex-startItems align to the start of the container.
flex-endItems align to the end of the container.
centerItems align at the center of the container.
stretchItems are stretched to fit the container.
baselineItems align at their baseline.

Example

jsx
<View style={{ alignItems: 'center' }}>
  <Text>Centered Item</Text>
</View>

4. Align Self (alignSelf)

ValueDescription
autoInherits its container's alignItems value.
flex-startAligns to the start of the container.
flex-endAligns to the end of the container.
centerAligns at the center of the container.
stretchStretches to fit the container.
baselineAligns at the baseline of the container.
jsx
<View style={{ alignItems: 'flex-start' }}>
  <Text style={{ alignSelf: 'center' }}>Centered Item</Text>
</View>

5. Flex Wrap (flexWrap)

ValueDescription
nowrapItems will not wrap.
wrapItems will wrap if they run out of room.
wrap-reverseItems will wrap in reverse.

Example

jsx
Value	Description
nowrap	Items will not wrap.
wrap	Items will wrap if they run out of room.
wrap-reverse	Items will wrap in reverse

6. Flex (flex)

ValueDescription
Number (e.g., 1)A shorthand for setting flexGrow, flexShrink, and flexBasis.

Example

jsx
<View style={{ flex: 1 }}>
  <Text>Flexible Item</Text>
</View>

7. Flex Grow (flexGrow) & 8. Flex Shrink (flexShrink)

ValueDescription
Number (e.g., 2)Defines the ability for an item to grow/shrink if necessary.

Example

jsx
<View style={{ flexGrow: 2 }}>
  <Text>Growing Item</Text>
</View>

9. Flex Basis (flexBasis)

ValueDescription
Percentage or Absolute ValueDefines the default size of an element before the remaining space is distributed.

Example

jsx
<View style={{ flexBasis: '50%' }}>
  <Text>Item taking up half the space</Text>
</View>

10. Align Content (alignContent)

ValueDescription
flex-startLines align to the start of the container.
flex-endLines align to the end of the container.
centerLines align at the center of the container.
stretchLines are stretched to fit the container.
space-betweenLines display with equal spacing between them.
space-aroundLines display with equal spacing around them.

Example

jsx
<View style={{ alignContent: 'center' }}>
  <Text>Centered Content</Text>
</View>
ESCRITOS DE VÍCTOR