0
0
React Nativemobile~20 mins

Flexbox layout (flexDirection, justifyContent, alignItems) in React Native - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Flexbox Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
rendering
intermediate
2:00remaining
What is the layout direction of this React Native Flexbox?
Consider this React Native style applied to a container:
{
  flexDirection: 'row'
}

How will the child elements be arranged visually?
React Native
import React from 'react';
import { View, Text } from 'react-native';

export default function App() {
  return (
    <View style={{ flexDirection: 'row', borderWidth: 1, padding: 10 }}>
      <Text>A</Text>
      <Text>B</Text>
      <Text>C</Text>
    </View>
  );
}
AChildren are arranged horizontally, side by side from left to right.
BChildren are stacked vertically, one on top of another.
CChildren overlap each other in the same position.
DChildren are arranged in a grid with two columns.
Attempts:
2 left
💡 Hint
flexDirection controls the main axis direction of children.
rendering
intermediate
2:00remaining
How does justifyContent: 'space-between' affect child elements?
Given this style:
{
  flexDirection: 'row',
  justifyContent: 'space-between'
}

How will the children be spaced inside the container?
React Native
import React from 'react';
import { View, Text } from 'react-native';

export default function App() {
  return (
    <View style={{ flexDirection: 'row', justifyContent: 'space-between', borderWidth: 1, padding: 10 }}>
      <Text>A</Text>
      <Text>B</Text>
      <Text>C</Text>
    </View>
  );
}
AChildren are centered with equal space around each child.
BChildren are evenly spaced with equal space between them and edges.
CChildren are grouped together at the start with no space between.
DChildren are spaced so the first is at start, last at end, and equal space between others.
Attempts:
2 left
💡 Hint
justifyContent controls spacing along the main axis.
rendering
advanced
2:00remaining
What is the vertical alignment of children with alignItems: 'center'?
Given this style:
{
  flexDirection: 'row',
  alignItems: 'center',
  height: 100
}

How will the children be aligned vertically inside the container?
React Native
import React from 'react';
import { View, Text } from 'react-native';

export default function App() {
  return (
    <View style={{ flexDirection: 'row', alignItems: 'center', height: 100, borderWidth: 1 }}>
      <Text style={{ fontSize: 20 }}>A</Text>
      <Text style={{ fontSize: 30 }}>B</Text>
      <Text style={{ fontSize: 40 }}>C</Text>
    </View>
  );
}
AChildren are aligned at the bottom edge of the container.
BChildren are vertically centered within the container.
CChildren are aligned at the top edge of the container.
DChildren stretch to fill the container height.
Attempts:
2 left
💡 Hint
alignItems controls alignment on the cross axis.
🧠 Conceptual
advanced
2:00remaining
Which flexDirection value stacks children vertically from bottom to top?
In React Native Flexbox, which flexDirection value arranges children vertically but starts from the bottom going up?
A'column-reverse'
B'row'
C'column'
D'row-reverse'
Attempts:
2 left
💡 Hint
The '-reverse' suffix reverses the order along the main axis.
accessibility
expert
3:00remaining
How to ensure keyboard navigation order matches visual order in reversed flexDirection?
If a container uses flexDirection: 'row-reverse' to visually reverse children order, what should you do to keep keyboard navigation logical and accessible?
AUse <code>accessibilityElementsHidden</code> on all children except the first.
BWrap children in a <code>ScrollView</code> to fix navigation order.
CManually set <code>tabIndex</code> or focus order to match visual order.
DNo action needed; keyboard navigation automatically matches visual order.
Attempts:
2 left
💡 Hint
Visual order and keyboard order can differ when using reversed flex directions.