← Back to Chapters

Responsive Layout in React Native

? Responsive Layout in React Native

? Quick Overview

Responsive layout in React Native allows apps to adapt smoothly to different screen sizes, orientations, and devices using Flexbox, Dimensions, and Platform APIs.

? Key Concepts

  • Flexbox-based layout system
  • Percentage and relative dimensions
  • Screen orientation handling
  • Platform-specific styling

? Syntax / Theory

React Native uses Flexbox by default. Layouts are defined using flex, flexDirection, justifyContent, and alignItems.

? View Code Example
// Basic responsive container using Flexbox
import { View, Text, StyleSheet } from "react-native";

export default function App() {
  return (
    <View style={styles.container}>
      <Text style={styles.box}>Box 1</Text>
      <Text style={styles.box}>Box 2</Text>
      <Text style={styles.box}>Box 3</Text>
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    flexDirection: "row",
    justifyContent: "space-around",
    alignItems: "center"
  },
  box: {
    padding: 20,
    backgroundColor: "#2563eb",
    color: "#fff"
  }
});

? Live Output / Explanation

The boxes automatically adjust their spacing and alignment based on the screen width. Flexbox ensures consistency across different devices.

? Interactive Example

Simulate React Native Flexbox properties to see how the layout adapts. Adjust the controls below:

1
2
3

? Use Cases

  • Mobile apps supporting phones and tablets
  • Orientation-aware dashboards
  • Reusable UI components

? Tips & Best Practices

  • Prefer Flexbox over fixed dimensions
  • Use Dimensions API sparingly
  • Test layouts on multiple screen sizes

? Try It Yourself

  • Change flexDirection to column
  • Add more boxes and test spacing
  • Handle orientation using useWindowDimensions