Layout Systems: Flexbox, Rows, Columns & Stacks
Position elements with the layout model of your stack: Flexbox in React Native, Row/Column in Flutter and Compose, stacks in SwiftUI.
Beginner · about 6 hours · difficulty 2/5
Learn first: Components, Props & Styling
Mobile layout systems are all variations of the same few ideas: place children in a row or column, decide how extra space is shared, and align them on the cross axis.
React Native: Flexbox
- Default
flexDirectioniscolumn(unlike the web). justifyContentdistributes along the main axis,alignItemsalong the cross axis.flex: 1makes a child fill the remaining space;gapadds spacing between children.- Use
position: "absolute"sparingly for overlays and badges.
Flutter and Compose
Row,ColumnandStack(Flutter) orRow,Column,Box(Compose).Expanded/Flexible(Flutter) orModifier.weight()(Compose) share space.- Flutter's rule: *constraints go down, sizes go up, parent sets position*. Most overflow errors come from unbounded constraints.
SwiftUI
HStack, VStack, ZStack, Spacer and .frame(). Views size themselves from content; modifiers wrap views, so modifier order changes the result.
Pitfalls
- Nesting scroll views in the same direction.
- Fixed widths and heights that break on small phones or large fonts.
Good enough to move on: you can recreate a profile header (avatar, name, stats row, follow button) from a screenshot without fixed pixel positions.
Key concepts
- Main axis and cross axis
- Flexbox in React Native
- Row, Column and Stack widgets: Flutter and Compose
- HStack, VStack and ZStack: SwiftUI
- Sharing space: flex, Expanded, weight
- Absolute positioning and overlays
- Flutter constraints model: Essential if you chose Flutter
Mini project
Clone the layout of a music player screen (album art, title, progress bar, controls row) that looks right on both a small and a large phone.
Check yourself
What does flex: 1 do on a child inside a column, and what happens if its parent has no defined height?
Free resources
- React Native: Layout with Flexbox (React Native)
- Flutter: Layouts (Flutter)
- Compose layout basics (Android Developers)