Lesson 7 of 10
Responsive Design Patterns
A production mobile app must look great on a 4.7-inch iPhone SE and a 13-inch iPad Pro. Responsive design in React Native is density-independent pixels + proportional scaling + breakpoints.
Scaling Utilities
import { Dimensions, PixelRatio } from 'react-native';
const { width: SCREEN_WIDTH, height: SCREEN_HEIGHT } = Dimensions.get('window');
// Base design dimensions (from Figma, typically 375×812 for iPhone 14 Pro)
const BASE_WIDTH = 375;
const BASE_HEIGHT = 812;
// Linear scale - good for padding, margins, spacing
export const scale = (size: number) => (SCREEN_WIDTH / BASE_WIDTH) * size;
// Moderate scale - good for font sizes (prevents text from scaling too aggressively)
export const moderateScale = (size: number, factor = 0.5) =>
size + (scale(size) - size) * factor;
// Vertical scale - good for heights
export const verticalScale = (size: number) => (SCREEN_HEIGHT / BASE_HEIGHT) * size;
// Convert dp to physical pixels (for hairline borders)
export const hairlineWidth = 1 / PixelRatio.get();
// Breakpoints
export const BREAKPOINTS = { phone: 0, tablet: 768, desktop: 1024 } as const;
export function isTablet() { return SCREEN_WIDTH >= BREAKPOINTS.tablet; }
// ---- Responsive hook ----
function useBreakpoint() {
const { width } = useWindowDimensions();
if (width >= 1024) return 'desktop' as const;
if (width >= 768) return 'tablet' as const;
return 'phone' as const;
}
// ---- Usage ----
const styles = StyleSheet.create({
title: {
fontSize: moderateScale(20), // ~20 on iPhone SE, ~22 on iPhone 14 Pro Max, ~24 on iPad
padding: scale(16), // proportional padding
},
});Adaptive Layouts for Tablet
function ProductDetail({ product }: { product: Product }) {
const breakpoint = useBreakpoint();
if (breakpoint === 'tablet') {
// iPad: image on left, details on right (side-by-side)
return (
<View style={{ flex: 1, flexDirection: 'row', padding: 32 }}>
<View style={{ flex: 1 }}>
<Image source={{ uri: product.imageUri }} style={{ width: '100%', aspectRatio: 1, borderRadius: 16 }} />
</View>
<View style={{ flex: 1, paddingLeft: 32 }}>
<ProductInfo product={product} />
</View>
</View>
);
}
// Phone: image stacked above details
return (
<ScrollView>
<Image source={{ uri: product.imageUri }} style={{ width: '100%', aspectRatio: 4 / 3 }} />
<View style={{ padding: 16 }}>
<ProductInfo product={product} />
</View>
</ScrollView>
);
}Tip
Tip
Practice Responsive Design Patterns in small, isolated examples before integrating into larger projects. Breaking concepts into small experiments builds genuine understanding faster than reading alone.
Adapting layouts across phone, foldable, and tablet screen dimensions
Practice Task
Note
Practice Task - (1) Write a working example of Responsive Design Patterns from scratch without looking at notes. (2) Modify it to handle an edge case (empty input, null value, or error state). (3) Share your solution in the Priygop community for feedback.
Quick Quiz
Common Mistake
Warning
A common mistake with Responsive Design Patterns is skipping edge case testing - empty inputs, null values, and unexpected data types. Always validate boundary conditions to write robust, production-ready react native code.
Finished this lesson?