Lesson 9 of 10
Mini Project: Responsive Profile with Stats Grid
Build a responsive profile screen with a contacts list, a stats grid, and a photo grid that adapts between phone and tablet layouts. Combines FlatList, SafeAreaView, useWindowDimensions, and responsive scaling.
Responsive Profile with Photo Grid
import React from 'react';
import { View, Text, FlatList, StyleSheet, Pressable } from 'react-native';
import { Image } from 'expo-image';
import { SafeAreaView } from 'react-native-safe-area-context';
import { useWindowDimensions } from 'react-native';
const PHOTOS = Array.from({ length: 18 }, (_, i) => ({
id: String(i),
uri: `https://picsum.photos/seed/${i + 1}/300/300`,
}));
const STATS = [
{ label: 'Posts', value: '284' },
{ label: 'Following', value: '1.2K' },
{ label: 'Followers', value: '48.3K' },
];
// Memoized photo cell
const PhotoCell = React.memo(({ uri, size }: { uri: string; size: number }) => (
<Image
source={{ uri }}
style={{ width: size, height: size }}
contentFit="cover"
transition={100}
recyclingKey={uri}
/>
));
export default function ResponsiveProfile() {
const { width } = useWindowDimensions();
const isTablet = width >= 768;
const numCols = isTablet ? 4 : 3;
const gap = 2;
const photoSize = (width - gap * (numCols - 1)) / numCols;
const Header = (
<View>
{/* Profile info */}
<View style={[styles.profileHeader, isTablet && styles.profileHeaderTablet]}>
<Image
source={{ uri: 'https://i.pravatar.cc/200?u=profile' }}
style={[styles.avatar, isTablet && styles.avatarTablet]}
contentFit="cover"
/>
<View style={isTablet ? styles.profileInfoTablet : undefined}>
<Text style={styles.name}>Sarah Chen</Text>
<Text style={styles.bio} numberOfLines={2}>
Senior Mobile Engineer · React Native contributor 🚀
</Text>
{/* Stats */}
<View style={styles.statsRow}>
{STATS.map((s, i) => (
<React.Fragment key={s.label}>
<View style={styles.stat}>
<Text style={styles.statVal}>{s.value}</Text>
<Text style={styles.statLbl}>{s.label}</Text>
</View>
{i < STATS.length - 1 && <View style={styles.divider} />}
</React.Fragment>
))}
</View>
<Pressable
style={styles.followBtn}
android_ripple={{ color: '#ffffff30' }}
accessibilityRole="button"
accessibilityLabel="Follow Sarah Chen"
>
<Text style={styles.followBtnText}>+ Follow</Text>
</Pressable>
</View>
</View>
{/* Tab bar */}
<View style={styles.tabs}>
<Text style={[styles.tab, styles.tabActive]}>⊞ Grid</Text>
<Text style={styles.tab}>↯ Reels</Text>
<Text style={styles.tab}>🏷 Tagged</Text>
</View>
</View>
);
return (
<SafeAreaView style={styles.screen} edges={['top']}>
<FlatList
data={PHOTOS}
key={numCols} // re-mount when columns change
numColumns={numCols}
renderItem={({ item }) => <PhotoCell uri={item.uri} size={photoSize} />}
keyExtractor={item => item.id}
ListHeaderComponent={Header}
ItemSeparatorComponent={() => <View style={{ height: gap }} />}
columnWrapperStyle={{ gap }}
showsVerticalScrollIndicator={false}
initialNumToRender={numCols * 4}
/>
</SafeAreaView>
);
}
const styles = StyleSheet.create({
screen: { flex: 1, backgroundColor: '#0f172a' },
profileHeader: { padding: 20, gap: 16 },
profileHeaderTablet: { flexDirection: 'row', alignItems: 'flex-start', gap: 32 },
avatar: { width: 80, height: 80, borderRadius: 40 },
avatarTablet: { width: 120, height: 120, borderRadius: 60 },
profileInfoTablet: { flex: 1 },
name: { fontSize: 18, fontWeight: '700', color: '#f1f5f9', marginBottom: 4 },
bio: { fontSize: 13, color: '#94a3b8', lineHeight: 18, marginBottom: 12 },
statsRow: { flexDirection: 'row', alignItems: 'center', marginBottom: 14 },
stat: { flex: 1, alignItems: 'center' },
statVal: { fontSize: 17, fontWeight: '700', color: '#f1f5f9' },
statLbl: { fontSize: 12, color: '#64748b' },
divider: { width: 1, height: 28, backgroundColor: '#334155' },
followBtn: { backgroundColor: '#229c6b', borderRadius: 8, paddingVertical: 10, alignItems: 'center' },
followBtnText: { color: 'white', fontWeight: '700', fontSize: 15 },
tabs: { flexDirection: 'row', borderTopWidth: 1, borderTopColor: '#1e293b' },
tab: { flex: 1, textAlign: 'center', paddingVertical: 12, color: '#64748b', fontSize: 18 },
tabActive: { color: '#f1f5f9', borderTopWidth: 2, borderTopColor: '#229c6b' },
});Tip
Tip
Practice Mini Project Responsive Profile with Stats Grid in small, isolated examples before integrating into larger projects. Breaking concepts into small experiments builds genuine understanding faster than reading alone.
Adaptive multi-column analytics grid with dynamic screen dimensions
Practice Task
Note
Practice Task - (1) Write a working example of Mini Project Responsive Profile with Stats Grid 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 Mini Project Responsive Profile with Stats Grid 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?