Skip to the page

Components, layout and platform differences · core

Yoga flexbox and responsive screens

React Native lays out views with Yoga, a flexbox engine whose defaults differ from the web (column direction, flexShrink 0, alignContent flex-start, flex as a single number), and responsive screens come from useWindowDimensions, flex rules and breakpoints, not device checks.

The notes

What you must know

  • Defaults that differ from the web: flexDirection "column", alignContent "flex-start", flexShrink 0, flex accepts one number only, position "relative", boxSizing "border-box".
  • flex: N means flexGrow N, flexShrink 1, flexBasis 0, so siblings share free space by ratio. flexGrow: 1 alone grows from the item's own size (basis auto), so results differ when content sizes differ.
  • flex: 0 sizes the item from width/height and it never grows or shrinks; flex: -1 can shrink down to minWidth/minHeight.
  • An absolute child is placed against the nearest ancestor that is not static (position: "static" is New Architecture only). gap, rowGap and columnGap work; percentage gap needs the New Architecture.
  • useWindowDimensions() re-renders on size changes; Dimensions.get() is a one-time snapshot. Landscape = width > height.
  • Apps built with the iOS 27 SDK run in resizable windows on iPad; 0.88 keeps Dimensions and useWindowDimensions up to date. Use breakpoints by width, not "isTablet".
  • Respect the user's font size: cap it with maxFontSizeMultiplier instead of disabling scaling.

The red pen

Common traps: mistake → fix

  • Mistake: "The default flexDirection is row"

    Fix: it is column in React Native.

  • Mistake: "flex: 1 is the same as flexGrow: 1"

    Fix: flex: 1 uses basis 0; flexGrow: 1 uses basis auto.

  • Mistake: "Read Dimensions once at module load"

    Fix: it goes stale on rotation, split screen and resizable windows.

Easy to hard

Questions interviewers ask, easy to hard

  1. How is flexbox in React Native different from the web?
  2. flex: 1 vs flexGrow: 1: what is the difference?
  3. How do you detect portrait vs landscape?
  4. How do you build one layout for phones, tablets, foldables and resizable iPad windows?

Explain it out loud

Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.

Practise by voice

Your first interview is free

Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.

Start your free interview