React Native course · Module 1: Your first app
PROJECT: Atlantis Citizen Card
In this lesson4
Time for practice! Let's create an interactive Atlantis citizen card, combining all the components we've learned.
Project Goal
We will create a profile screen with:
- Profile picture
- Citizen data
- Statistics
- Action buttons
Implementation
import {
SafeAreaView,
ScrollView,
View,
Text,
Image,
Pressable,
StyleSheet,
Alert
} from 'react-native';
import { useState } from 'react';
interface Citizen {
name: string;
title: string;
avatar: string;
level: number;
guild: string;
stats: {
treasures: number;
expeditions: number;
reputation: number;
};
skills: string[];
}
export default function CitizenCard() {
const [citizen] = useState<Citizen>({
name: 'Nereus Oceanborn',
title: 'Guardian of the Depths',
avatar: 'https://i.pravatar.cc/150?img=68',
level: 42,
guild: 'Order of the Trident',
stats: {
treasures: 1247,
expeditions: 89,
reputation: 9450,
},
skills: ['Trident mastery', 'Current control', 'Sea speech', 'Navigation'],
});
const [isFollowing, setIsFollowing] = useState(false);
const handleFollow = () => {
setIsFollowing(!isFollowing);
Alert.alert(
isFollowing ? 'Unfollowed' : 'Following!',
isFollowing
? `You are no longer following ${citizen.name}`
: `You are now following ${citizen.name}`
);
};
const handleMessage = () => {
Alert.alert('Message', `Send a message to ${citizen.name}`);
};
return (
<SafeAreaView style={styles.container}>
<ScrollView contentContainerStyle={styles.scrollContent}>
{/* Header with gradient */}
<View style={styles.header}>
<View style={styles.levelBadge}>
<Text style={styles.levelText}>Lvl {citizen.level}</Text>
</View>
</View>
{/* Avatar */}
<View style={styles.avatarContainer}>
<Image
source={{ uri: citizen.avatar }}
style={styles.avatar}
/>
<View style={styles.statusDot} />
</View>
{/* Basic information */}
<View style={styles.infoSection}>
<Text style={styles.name}>{citizen.name}</Text>
<Text style={styles.title}>{citizen.title}</Text>
<View style={styles.guildBadge}>
<Text style={styles.guildText}>{citizen.guild}</Text>
</View>
</View>
{/* Statistics */}
<View style={styles.statsContainer}>
<View style={styles.statItem}>
<Text style={styles.statValue}>{citizen.stats.treasures}</Text>
<Text style={styles.statLabel}>Treasures</Text>
</View>
<View style={styles.statDivider} />
<View style={styles.statItem}>
<Text style={styles.statValue}>{citizen.stats.expeditions}</Text>
<Text style={styles.statLabel}>Expeditions</Text>
</View>
<View style={styles.statDivider} />
<View style={styles.statItem}>
<Text style={styles.statValue}>{citizen.stats.reputation}</Text>
<Text style={styles.statLabel}>Reputation</Text>
</View>
</View>
{/* Skills */}
<View style={styles.skillsSection}>
<Text style={styles.sectionTitle}>Skills</Text>
<View style={styles.skillsGrid}>
{citizen.skills.map((skill, index) => (
<View key={index} style={styles.skillChip}>
<Text style={styles.skillText}>{skill}</Text>
</View>
))}
</View>
</View>
{/* Action buttons */}
<View style={styles.actionsContainer}>
<Pressable
style={({ pressed }) => [
styles.actionButton,
isFollowing ? styles.followingButton : styles.followButton,
pressed && styles.buttonPressed,
]}
onPress={handleFollow}
>
<Text style={[
styles.actionButtonText,
isFollowing && styles.followingButtonText
]}>
{isFollowing ? 'Following' : '+ Follow'}
</Text>
</Pressable>
<Pressable
style={({ pressed }) => [
styles.actionButton,
styles.messageButton,
pressed && styles.buttonPressed,
]}
onPress={handleMessage}
>
<Text style={styles.actionButtonText}>Message</Text>
</Pressable>
</View>
{/* Bio */}
<View style={styles.bioSection}>
<Text style={styles.sectionTitle}>About Me</Text>
<Text style={styles.bioText}>
Guardian of the Depths for 15 years. I specialize in exploring
sunken ruins and protecting the treasures of Atlantis. Looking for companions
for the next expeditions into unknown corners of the ocean.
</Text>
</View>
</ScrollView>
</SafeAreaView>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#1a5276',
},
scrollContent: {
paddingBottom: 30,
},
header: {
height: 120,
backgroundColor: '#2980b9',
borderBottomLeftRadius: 30,
borderBottomRightRadius: 30,
},
levelBadge: {
position: 'absolute',
top: 16,
right: 16,
backgroundColor: '#f39c12',
paddingHorizontal: 12,
paddingVertical: 6,
borderRadius: 12,
},
levelText: {
color: '#fff',
fontWeight: 'bold',
fontSize: 14,
},
avatarContainer: {
alignItems: 'center',
marginTop: -50,
},
avatar: {
width: 120,
height: 120,
borderRadius: 60,
borderWidth: 4,
borderColor: '#1a5276',
},
statusDot: {
position: 'absolute',
bottom: 8,
right: '35%',
width: 20,
height: 20,
borderRadius: 10,
backgroundColor: '#2ecc71',
borderWidth: 3,
borderColor: '#1a5276',
},
infoSection: {
alignItems: 'center',
marginTop: 12,
},
name: {
fontSize: 24,
fontWeight: 'bold',
color: '#fff',
},
title: {
fontSize: 16,
color: '#aed6f1',
marginTop: 4,
},
guildBadge: {
marginTop: 12,
backgroundColor: '#34495e',
paddingHorizontal: 16,
paddingVertical: 8,
borderRadius: 20,
},
guildText: {
color: '#f1c40f',
fontWeight: '600',
fontSize: 14,
},
statsContainer: {
flexDirection: 'row',
justifyContent: 'center',
alignItems: 'center',
marginTop: 24,
marginHorizontal: 20,
backgroundColor: '#2c3e50',
borderRadius: 16,
paddingVertical: 20,
},
statItem: {
flex: 1,
alignItems: 'center',
},
statValue: {
fontSize: 22,
fontWeight: 'bold',
color: '#fff',
},
statLabel: {
fontSize: 12,
color: '#95a5a6',
marginTop: 4,
},
statDivider: {
width: 1,
height: 40,
backgroundColor: '#34495e',
},
skillsSection: {
marginTop: 24,
paddingHorizontal: 20,
},
sectionTitle: {
fontSize: 18,
fontWeight: 'bold',
color: '#fff',
marginBottom: 12,
},
skillsGrid: {
flexDirection: 'row',
flexWrap: 'wrap',
gap: 8,
},
skillChip: {
backgroundColor: '#34495e',
paddingHorizontal: 12,
paddingVertical: 8,
borderRadius: 16,
},
skillText: {
color: '#fff',
fontSize: 14,
},
actionsContainer: {
flexDirection: 'row',
gap: 12,
marginTop: 24,
paddingHorizontal: 20,
},
actionButton: {
flex: 1,
paddingVertical: 14,
borderRadius: 12,
alignItems: 'center',
},
followButton: {
backgroundColor: '#3498db',
},
followingButton: {
backgroundColor: 'transparent',
borderWidth: 2,
borderColor: '#3498db',
},
messageButton: {
backgroundColor: '#27ae60',
},
buttonPressed: {
opacity: 0.8,
transform: [{ scale: 0.98 }],
},
actionButtonText: {
color: '#fff',
fontSize: 16,
fontWeight: '600',
},
followingButtonText: {
color: '#3498db',
},
bioSection: {
marginTop: 24,
paddingHorizontal: 20,
},
bioText: {
fontSize: 15,
color: '#bdc3c7',
lineHeight: 22,
},
});What Does the Project Include?
- Component composition - View, Text, Image, ScrollView, Pressable
- State management - useState for follow handling
- Conditional styles - changing the follow button appearance
- Responsiveness - flexDirection, flex, gap
- Interaction - Alert, onPress
- TypeScript - interface for data
Tasks for Independent Work
- Add the ability to edit the bio
- Implement an animation when clicking on the avatar
- Add a "Recent Expeditions" section with a list
- Create a modal with full statistics
Congratulations! You have completed the first module in Atlantis!
Docs entries used in this lesson
Spotted a mistake in this lesson?
Check yourself
Answer the questions from this lesson. Pick an answer to see right away whether it is correct.
1. What is the default flexDirection in React Native?
Hands-on tasks in the game
- Code editor
Fill in the styles for View
- Code editor
Fill in the Pressable component