← Back to Chapters

Stack Navigation Styling

? Stack Navigation Styling

? Quick Overview

Stack Navigation styling in React Native allows you to customize headers, transitions, colors, titles, and gestures for screens managed by createNativeStackNavigator or createStackNavigator.

? Key Concepts

  • Global header styling using screenOptions
  • Per-screen customization using options
  • Header title, colors, and alignment
  • Custom header components
  • Gesture and animation styling

? Syntax / Theory

Stack navigator styling is controlled using configuration objects. You can apply styles globally or override them for individual screens.

? View Code Example
// Import stack navigator from React Navigation
import { createNativeStackNavigator } from "@react-navigation/native-stack";

const Stack = createNativeStackNavigator();

function AppStack() {
  return (
    <Stack.Navigator
      screenOptions={{
        headerStyle: { backgroundColor: "#2563eb" },
        headerTintColor: "#ffffff",
        headerTitleStyle: { fontWeight: "bold" }
      }}
    >
      <Stack.Screen name="Home" component={HomeScreen} />
    </Stack.Navigator>
  );
}

? Live Output / Explanation

The header background becomes blue, text turns white, and the title appears bold across all stack screens.

? Interactive Example

Use the simulator below to experiment with header styling properties. Change the controls to see how the code and the mobile preview update in real-time.

? Styling Controls

screenOptions={{
  headerStyle: { backgroundColor: '#2563eb' },
  headerTintColor: '#ffffff',
  headerTitleAlign: 'left'
}}
Home Screen
Screen Content Area
? View Dynamic Code Example
// Dynamic header color using props
options={{
  headerStyle: {
    backgroundColor: route.params?.color || "#16a34a"
  }
}}

? Use Cases

  • Brand-based header theming
  • Dark / light mode navigation headers
  • Custom back buttons and titles
  • Screen-specific animations

✅ Tips & Best Practices

  • Use screenOptions for consistency
  • Override only when required per screen
  • Keep header styles simple for performance
  • Match navigation style with app theme

? Try It Yourself

  • Change header height and alignment
  • Add a custom header title component
  • Implement animated transitions
  • Switch header styles based on theme toggle