π¬ React Native Navigation: Screen Configuration
The Movie Theater Analogy π₯
Imagine youβre building a movie theater. Each screen in your app is like a different movie room. But what makes each room special? The decorations, signs, doors, and how you walk between rooms!
Thatβs exactly what Screen Configuration does in React Native Navigation. It lets you customize how each βroomβ (screen) looks and behaves.
π― What Weβll Learn
graph TD A["Screen Configuration"] --> B["Screen Options"] A --> C["Header Title"] A --> D["Header Style"] A --> E["Header Components"] A --> F["Modal Screens"] A --> G["Screen Transitions"] A --> H["Custom Transitions"]
1οΈβ£ Screen Options: The Control Panel
What Is It?
Think of Screen Options as a remote control for your screen. Just like a TV remote lets you change volume, brightness, and channels, screenOptions lets you change how your screen looks and behaves!
Simple Example
<Stack.Navigator
screenOptions={{
headerShown: true,
gestureEnabled: true,
}}
>
<Stack.Screen name="Home" />
</Stack.Navigator>
Real-Life Comparison
| TV Remote Button | Screen Option |
|---|---|
| Power On/Off | headerShown: true/false |
| Volume | gestureEnabled |
| Picture Mode | presentation |
Per-Screen Options
You can also set options for just ONE screen:
<Stack.Screen
name="Profile"
options={{
headerShown: false,
}}
/>
Pro Tip: Options set on a specific screen override the navigatorβs screenOptions!
2οΈβ£ Header Title: The Room Sign
What Is It?
Every movie room has a sign saying what movie is playing. The Header Title is that sign for your screen!
Three Ways to Set It
Way 1: Automatic (from name)
<Stack.Screen name="My Profile" />
// Shows "My Profile" in header
Way 2: Using title option
<Stack.Screen
name="Profile"
options={{ title: 'My Account' }}
/>
Way 3: Dynamic title (changes based on data)
<Stack.Screen
name="UserProfile"
options={({ route }) => ({
title: route.params?.userName ?? 'Profile'
})}
/>
Visual Example
βββββββββββββββββββββββββββββββ
β β β My Account β β
βββββββββββββββββββββββββββββββ€
β β
β Screen Content β
β β
βββββββββββββββββββββββββββββββ
3οΈβ£ Header Style: Painting the Sign
What Is It?
Now that you have a sign, letβs make it beautiful! Header Style is like choosing paint colors and decorations for your sign.
The Paint Buckets
<Stack.Screen
name="Home"
options={{
headerStyle: {
backgroundColor: '#6366f1',
},
headerTintColor: '#ffffff',
headerTitleStyle: {
fontWeight: 'bold',
fontSize: 18,
},
}}
/>
What Each Property Does
| Property | What It Paints |
|---|---|
headerStyle |
The background (header bar itself) |
headerTintColor |
Back button & title text color |
headerTitleStyle |
Font styling for title |
Quick Visual
Before: After:
βββββββββββββββββ βββββββββββββββββ
β β β Home β β β ββββββββββββββββ Purple!
β β (gray) β β β β Home β β White text!
βββββββββββββββββ βββββββββββββββββ
4οΈβ£ Header Components: Custom Decorations
What Is It?
Sometimes a sign isnβt enough! You want to add a bell, search glass, or profile picture to your header. Thatβs what Header Components do!
The Three Spots
<Stack.Screen
name="Home"
options={{
headerLeft: () => (
<MenuButton />
),
headerRight: () => (
<SearchIcon />
),
headerTitle: () => (
<LogoImage />
),
}}
/>
Where They Go
βββββββββββββββββββββββββββββββββββββββ
β [headerLeft] [headerTitle] [headerRight] β
βββββββββββββββββββββββββββββββββββββββ
Example:
βββββββββββββββββββββββββββββββββββββββ
β β° β π MyApp β π π β
βββββββββββββββββββββββββββββββββββββββ
Complete Example
options={{
headerRight: () => (
<View style={{ flexDirection: 'row' }}>
<TouchableOpacity
onPress={() => alert('Search!')}
>
<Icon name="search" size={24} />
</TouchableOpacity>
</View>
),
}}
5οΈβ£ Modal Screens: The Pop-Up Window
What Is It?
Imagine watching a movie, and suddenly a small window pops up asking βDo you want popcorn?β Thatβs a Modal! It slides up from the bottom and covers most of the screen.
How Modals Are Different
| Regular Screen | Modal Screen |
|---|---|
| Slides from right β | Slides from bottom β |
| Full screen | Can show previous screen behind |
| Back button | Swipe down to close |
Setting Up Modals
Step 1: Create a Group for Modals
<Stack.Navigator>
<Stack.Group>
<Stack.Screen name="Home" />
<Stack.Screen name="Profile" />
</Stack.Group>
<Stack.Group
screenOptions={{ presentation: 'modal' }}
>
<Stack.Screen name="Settings" />
<Stack.Screen name="Help" />
</Stack.Group>
</Stack.Navigator>
Step 2: Or Set on Single Screen
<Stack.Screen
name="Popup"
options={{ presentation: 'modal' }}
/>
Modal Presentation Options
// Different modal styles:
presentation: 'modal' // Standard modal
presentation: 'transparentModal' // See-through background
presentation: 'containedModal' // Stays in navigator bounds
presentation: 'fullScreenModal' // Full screen modal
6οΈβ£ Screen Transitions: How Doors Open
What Is It?
When you walk from one movie room to another, the door can open in different ways - swing, slide, or spin! Screen Transitions control how screens appear and disappear.
Built-in Animations
<Stack.Navigator
screenOptions={{
animation: 'slide_from_right',
}}
>
Animation Options
| Animation | What It Looks Like |
|---|---|
slide_from_right |
New screen slides in from right β |
slide_from_left |
New screen slides in from left β |
slide_from_bottom |
Slides up from bottom β |
fade |
Fades in smoothly β¨ |
none |
Instant, no animation β‘ |
flip |
Flips like a card π |
Per-Screen Animation
<Stack.Screen
name="Details"
options={{
animation: 'fade',
}}
/>
iOS vs Android Defaults
iOS Default: Android Default:
βββββ βββββ βββββ
β A βββ B β β A β fade β β B β
βββββ βββββ βββββ
(slide) (fade from bottom)
7οΈβ£ Custom Transitions: Design Your Own Door
What Is It?
The built-in animations are nice, but what if you want something unique? Custom Transitions let you create your own magical door animations!
The Ingredients
graph TD A["Custom Transition"] --> B["cardStyleInterpolator"] A --> C["gestureDirection"] A --> D["transitionSpec"] B --> E["Animate card position/opacity"] C --> F["Which way to swipe"] D --> G["Timing and spring config"]
Simple Custom Transition
import {
CardStyleInterpolators
} from '@react-navigation/stack';
<Stack.Screen
name="Special"
options={{
cardStyleInterpolator:
CardStyleInterpolators
.forHorizontalIOS,
}}
/>
Building From Scratch
const customTransition = {
cardStyleInterpolator: ({ current }) => ({
cardStyle: {
opacity: current.progress,
transform: [
{
scale: current.progress.interpolate({
inputRange: [0, 1],
outputRange: [0.9, 1],
}),
},
],
},
}),
};
<Stack.Screen
name="Fancy"
options={customTransition}
/>
What This Does
Start (progress = 0): End (progress = 1):
βββββββββββββββ βββββββββββββββ
β β β β
β Small & β β β Full & β
β Faded β β Visible β
β β β β
βββββββββββββββ βββββββββββββββ
90% size 100% size
0 opacity 1 opacity
Gesture Configuration
options={{
gestureEnabled: true,
gestureDirection: 'horizontal',
gestureResponseDistance: 100,
}}
| Gesture Property | What It Controls |
|---|---|
gestureEnabled |
Can swipe to go back? |
gestureDirection |
Swipe direction |
gestureResponseDistance |
How far from edge to start |
π Quick Reference Summary
graph TD A["Screen Config"] --> B["screenOptions"] A --> C["options"] B --> D["Apply to ALL screens"] C --> E["Apply to ONE screen"] D --> F["headerShown<br>gestureEnabled<br>animation"] E --> G["title<br>headerStyle<br>headerRight<br>presentation"]
π Golden Rules
screenOptions= Settings for ALL screens in a navigatoroptions= Settings for ONE specific screen- Specific beats general = Screen options override navigator options
- Modals slide up = Regular screens slide sideways
- Custom = Power = Build any transition you can imagine!
π What Youβve Mastered!
| Concept | You Can Now⦠|
|---|---|
| Screen Options | Control screen behavior globally |
| Header Title | Name your screens dynamically |
| Header Style | Make beautiful colored headers |
| Header Components | Add buttons and icons |
| Modal Screens | Create pop-up style screens |
| Screen Transitions | Use built-in animations |
| Custom Transitions | Build your own magic! |
Youβre now a Screen Configuration wizard! π§ββοΈ
Every screen in your app can be customized exactly how you want it. Go build something amazing!
