Responsive layout in React Native allows apps to adapt smoothly to different screen sizes, orientations, and devices using Flexbox, Dimensions, and Platform APIs.
React Native uses Flexbox by default. Layouts are defined using flex, flexDirection, justifyContent, and alignItems.
// 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"
}
});
The boxes automatically adjust their spacing and alignment based on the screen width. Flexbox ensures consistency across different devices.
Simulate React Native Flexbox properties to see how the layout adapts. Adjust the controls below:
Dimensions API sparinglyflexDirection to columnuseWindowDimensions