React Native · Mobile UI at native speed
How do you handle screen size, density and safe areas?
Short answer
Use density-independent units, read size with useWindowDimensions, and respect safe area insets. Avoid caching Dimensions at module load because it does not update on rotation or foldables.
React Native numbers in styles are density-independent pixels. The platform scales them by the device pixel ratio, so a 16 unit padding looks physically similar across phones. PixelRatio is only for cases where you need the raw scale, such as aligning to a hairline.
import { useWindowDimensions } from "react-native";
import { useSafeAreaInsets } from "react-native-safe-area-context";
export function Screen() {
const { width, height, fontScale } = useWindowDimensions();
const insets = useSafeAreaInsets();
const isTablet = width >= 768;
return (
<View style={{ paddingTop: insets.top, paddingBottom: insets.bottom }}>
<Text>{isTablet ? "Tablet layout" : "Phone layout"}</Text>
<Text>{Math.round(height)} x {Math.round(width)} at scale {fontScale}</Text>
</View>
);
}Rules that prevent layout bugs
- Use flex and percentages for fluid layouts instead of hard-coded screen widths
- Read dimensions inside render or a hook, not once at module scope
- Account for fontScale because users may enlarge system text
- Use safe-area-context rather than guessing notch heights
- Test on a small phone and a tablet, not only a large simulator
On Android, the status bar and navigation bar behaviour depends on the edge-to-edge configuration. On iOS, the home indicator area matters. A screen that ignores insets may put a button under the gesture bar and make it hard to tap.
Follow-ups you should expect
Interviewers use these to check whether the first answer was understanding or memorisation.
- 1What is a density-independent pixel?
- 2How do you support tablets and foldables?
- 3What happens if you ignore safe area insets?
- 4How do you handle large system font sizes?
Say it in the interview
I treat layout as fluid rather than screen-specific. I use flex and percentages, read size from useWindowDimensions so rotation and resizing are handled, and apply safe area insets for notches and gesture bars. I also respect fontScale and test on a small phone and a tablet, because a layout that only works on one simulator size usually breaks in the real world.
Use this as a model, not a script. Saying it in your own words is what makes it survive follow-up pressure.
Related questions
Reading is step one
Now say it out loud.
Understanding an answer and delivering it under pressure are different skills. Rehearse this topic in a live React Native mock interview and get scored feedback on depth, clarity and confidence.