Beginner-Friendly Topic
Take your time - it's perfectly normal to re-read this topic 2-3 times. Try the interactive code editor below to run code yourself. Use the Q&A section to check your understanding before moving on.You've got this!
Lesson 9 of 10
Mini Project: Profile Card
Put together everything from this module: View, Text, Image, Pressable, StyleSheet, Flexbox, and Platform API into a real profile card UI. This mirrors exactly what you'd build in a social app or a contact detail screen.
Profile Card Component
import React, { useState } from 'react';
import {
View, Text, Image, Pressable, ScrollView,
StyleSheet, Platform, StatusBar,
} from 'react-native';
// Types
interface Stat { label: string; value: string; }
interface UserProfile {
name: string;
username: string;
bio: string;
avatarUri: string;
isFollowing: boolean;
stats: Stat[];
}
// ---- Stat Cell ----
function StatCell({ label, value }: Stat) {
return (
<View style={styles.statCell}>
<Text style={styles.statValue}>{value}</Text>
<Text style={styles.statLabel}>{label}</Text>
</View>
);
}
// ---- Main Component ----
const MOCK_USER: UserProfile = {
name: 'Sarah Chen',
username: '@sarahchen',
bio: 'Senior Mobile Engineer @ Meta. React Native contributor. Building things that millions of people use. Coffee-powered. 🚀',
avatarUri: 'https://i.pravatar.cc/200?u=sarah',
isFollowing: false,
stats: [
{ label: 'Posts', value: '284' },
{ label: 'Following', value: '1.2K' },
{ label: 'Followers', value: '48.3K' },
],
};
export default function ProfileCard() {
const [user, setUser] = useState(MOCK_USER);
function toggleFollow() {
setUser(u => ({ ...u, isFollowing: !u.isFollowing }));
}
return (
<View style={styles.screen}>
<StatusBar barStyle="light-content" backgroundColor="#0f172a" />
<ScrollView contentContainerStyle={styles.scroll} showsVerticalScrollIndicator={false}>
{/* Avatar */}
<View style={styles.avatarContainer}>
<Image source={{ uri: user.avatarUri }} style={styles.avatar} />
</View>
{/* Name & username */}
<Text style={styles.name}>{user.name}</Text>
<Text style={styles.username}>{user.username}</Text>
{/* Bio */}
<Text style={styles.bio} numberOfLines={3}>{user.bio}</Text>
{/* Stats row */}
<View style={styles.statsRow}>
{user.stats.map((s, i) => (
<React.Fragment key={s.label}>
<StatCell label={s.label} value={s.value} />
{i < user.stats.length - 1 && <View style={styles.divider} />}
</React.Fragment>
))}
</View>
{/* Follow button */}
<Pressable
style={({ pressed }) => [
styles.followBtn,
user.isFollowing && styles.followingBtn,
pressed && styles.btnPressed,
]}
onPress={toggleFollow}
hitSlop={8}
android_ripple={{ color: '#ffffff30' }}
accessibilityRole="button"
accessibilityLabel={user.isFollowing ? 'Unfollow user' : 'Follow user'}
>
<Text style={[styles.followBtnText, user.isFollowing && styles.followingBtnText]}>
{user.isFollowing ? '✓ Following' : '+ Follow'}
</Text>
</Pressable>
</ScrollView>
</View>
);
}
const styles = StyleSheet.create({
screen: { flex: 1, backgroundColor: '#0f172a' },
scroll: { alignItems: 'center', paddingTop: 60, paddingBottom: 40, paddingHorizontal: 24 },
avatarContainer: {
width: 100, height: 100, borderRadius: 50,
borderWidth: 3, borderColor: '#229c6b',
marginBottom: 16,
...Platform.select({
ios: { shadowColor: '#229c6b', shadowOffset: { width: 0, height: 4 }, shadowOpacity: 0.5, shadowRadius: 8 },
android: { elevation: 8 },
}),
},
avatar: { width: 94, height: 94, borderRadius: 47 },
name: { fontSize: 22, fontWeight: '700', color: '#f1f5f9', marginBottom: 4 },
username: { fontSize: 15, color: '#229c6b', marginBottom: 12 },
bio: { fontSize: 14, color: '#94a3b8', textAlign: 'center', lineHeight: 22, marginBottom: 28 },
statsRow: {
flexDirection: 'row', alignItems: 'center',
backgroundColor: '#1e293b', borderRadius: 14,
paddingVertical: 16, paddingHorizontal: 8,
width: '100%', marginBottom: 24,
},
statCell: { flex: 1, alignItems: 'center' },
statValue: { fontSize: 18, fontWeight: '700', color: '#f1f5f9' },
statLabel: { fontSize: 12, color: '#64748b', marginTop: 2 },
divider: { width: 1, height: 32, backgroundColor: '#334155' },
followBtn: {
backgroundColor: '#229c6b', borderRadius: 12,
paddingVertical: 14, paddingHorizontal: 40,
minWidth: 180, alignItems: 'center',
},
followingBtn: { backgroundColor: 'transparent', borderWidth: 1.5, borderColor: '#229c6b' },
btnPressed: { opacity: 0.8 },
followBtnText: { color: 'white', fontWeight: '700', fontSize: 16 },
followingBtnText: { color: '#229c6b' },
});Tip
Tip
Practice Mini Project Profile Card in small, isolated examples before integrating into larger projects. Breaking concepts into small experiments builds genuine understanding faster than reading alone.
Interactive profile card with platform-specific elevation and shadow styling
Practice Task
Note
Practice Task - (1) Write a working example of Mini Project Profile Card 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 Profile Card 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?