Let's think about this for a moment
In React Native, every View's default flexDirection is 'column' (the opposite of web CSS's 'row' default) — child components are arranged top to bottom by default. Switching to flexDirection: 'row' arranges them side by side. justifyContent controls spacing along the main axis (flex-start, center, space-between), while alignItems controls alignment along the cross axis (flex-start, center, stretch).
Let's connect this to a real scenario
To build a header bar (logo on the left, menu icon on the right), just add flexDirection: 'row', justifyContent: 'space-between' to the View's style — the two children automatically get pushed apart. Adding flex: 1 to a child component's style makes it take up the available space — if you want responsive behavior across different screen sizes, using flex is better than fixed width/height.
Code Example
const styles = StyleSheet.create({
header: {
flexDirection: 'row',
justifyContent: 'space-between',
alignItems: 'center',
padding: 16,
},
content: {
flex: 1, // remaining space ကို ယူ
justifyContent: 'center',
alignItems: 'center',
},
});You'll be able to build a header bar with flexDirection: row and arrange the logo/icon side by side.5-Minute Try-It
Put 3 boxes inside a View with flexDirection: 'row' and try justifyContent with 'flex-start', 'center', and 'space-between'.
A Quick Heads-Up
flex: 1 might not work if the parent container doesn't have a defined height (the root View needs flex: 1 too) — pay attention to the parent-child flex chain.