Learning Objectives
By the end of this module, you’ll understand:- Flexbox fundamentals and layout principles
- Flex direction and wrapping
- Justify content and align items
- Flex sizing (grow, shrink, basis)
- Absolute positioning
- Common layout patterns
Flexbox Fundamentals
Flexbox is the primary layout system in React Native. Unlike CSS on the web, all components in React Native use Flexbox by default.Flex Direction
Controls the primary axis of layout:| Value | Description |
|---|---|
column | Vertical stack (default) |
row | Horizontal stack |
column-reverse | Vertical, reversed order |
row-reverse | Horizontal, reversed order |
Justify Content
Aligns children along the main axis:Justify Content Options:
flex-start(default) - Align to startflex-end- Align to endcenter- Center itemsspace-between- Even spacing, edges at container boundsspace-around- Even spacing including before first and after lastspace-evenly- Equal spacing between all items including edges
Align Items
Aligns children along the cross axis:Align Items Options:
stretch(default) - Stretch to fillflex-start- Align to cross-startflex-end- Align to cross-endcenter- Center on cross axisbaseline- Align text baselines
Align Self
Override alignItems for individual children:Flex Sizing
flex
Defines how a component grows relative to siblings:flexGrow
Same asflex, but respects base size:
flexShrink
Controls how components shrink when space is limited:flexBasis
Sets the initial size before flexGrow/flexShrink:Flex Wrap
Controls wrapping of flex items:Flex Wrap Options:
nowrap(default) - Single linewrap- Multi-line, top to bottomwrap-reverse- Multi-line, bottom to top
Align Content
Aligns wrapped lines within container (only works with flexWrap):flex-start, flex-end, center, stretch, space-between, space-around
Positioning
Relative Positioning (Default)
Elements positioned according to normal document flow:Absolute Positioning
Removes element from document flow:Absolute Fill Shortcut
Z-Index
Controls stacking order of positioned elements:Common Layout Patterns
Center Content
Row with Space Between
Sticky Footer
Sidebar Layout
Grid Layout
Card with Overlay
Gap Property
Modern way to space flex items:Layout Props Reference
Container Props
| Prop | Type | Description |
|---|---|---|
flex | number | Grow factor |
flexDirection | string | Layout direction |
flexWrap | string | Wrapping behavior |
justifyContent | string | Main axis alignment |
alignItems | string | Cross axis alignment |
alignContent | string | Wrapped lines alignment |
Item Props
| Prop | Type | Description |
|---|---|---|
alignSelf | string | Override container alignItems |
flexGrow | number | Growth factor |
flexShrink | number | Shrink factor |
flexBasis | number/string | Initial size |
Position Props
| Prop | Type | Description |
|---|---|---|
position | string | 'relative' or 'absolute' |
top | number | Offset from top |
bottom | number | Offset from bottom |
left | number | Offset from left |
right | number | Offset from right |
zIndex | number | Stacking order |
Best Practices
- Use flex: 1 for components that should fill available space
- Avoid fixed dimensions when possible - use flex and percentages
- Combine justifyContent + alignItems for centering
- Understand the axes: main axis = flexDirection, cross axis = perpendicular
- Use gap property instead of margins for spacing (when available)
- Test on different screen sizes - flexbox is responsive by default }