📚 A step-by-step header with an animated progress bar, for React Navigation 7 and Expo Router. It's a plain header for any Stack, so there's no provider or custom navigator to set up.
npm install react-native-step-navigationPeer dependencies (already in any Expo / React Navigation app): react-native-safe-area-context, react-native-svg.
Put the steps in a group and give its _layout the StepHeader:
// app/(signup)/_layout.tsx
import { Stack } from 'expo-router'
import { StepHeader } from 'react-native-step-navigation'
export default function SignupLayout() {
return (
<Stack screenOptions={{ header: (props) => <StepHeader {...props} /> }}>
{/* the declaration order is the step order */}
<Stack.Screen name="name" />
<Stack.Screen name="address" />
<Stack.Screen name="password" options={{ title: 'Almost done' }} />
</Stack>
)
}In the parent layout, hide its own header for the group: <Stack.Screen name="(signup)" options={{ headerShown: false }} />.
Navigate between steps as usual (router.push('/address'), <Link href="/address">).
import { createNativeStackNavigator } from '@react-navigation/native-stack' // or @react-navigation/stack
import { StepHeader } from 'react-native-step-navigation'
const Step = createNativeStackNavigator()
export function SignupSteps() {
return (
<Step.Navigator screenOptions={{ header: (props) => <StepHeader {...props} /> }}>
<Step.Screen name="Name" component={NameScreen} />
<Step.Screen name="Address" component={AddressScreen} />
<Step.Screen name="Password" component={PasswordScreen} />
</Step.Navigator>
)
}- Title:
options={{ title: '...' }}. The default isStep X of N(change it withformatTitle). - Hide the header:
options={{ headerShown: false }}. - Anything else (hide back, no progress bar, a custom back target): override
headeron that screen, e.g.options={{ header: (p) => <StepHeader {...p} showBack={false} /> }}. - A screen that isn't a step (for example a summary): leave it out of
steps. The header shows without a progress bar.
Wrap StepHeader once with your app's defaults (language, icons, colors, analytics) and use the wrapper in every flow:
import { StepHeader, StepHeaderProps } from 'react-native-step-navigation'
export function FlowHeader(props: StepHeaderProps) {
return (
<StepHeader
formatTitle={(step, total) => `Etapa ${step} de ${total}`}
backIcon={<IconArrow />}
closeIcon={<IconClose />}
progressBarStyle={{ color: colors.primary }}
{...props}
/>
)
}
// a flow with a help button and no close button
<Stack.Navigator screenOptions={{ header: (p) => <FlowHeader {...p} right={<HelpButton />} showClose={false} /> }}>
// a screen that goes back to a specific step (React Navigation 7: `popTo`, not `navigate`)
<Stack.Screen
name="Times"
component={TimesScreen}
options={{ header: (p) => <FlowHeader {...p} onBack={() => p.navigation.popTo('HowOften')} /> }}
/>navigation, route and options come from the stack's header callback. Spread {...props} to pass them.
| Prop | Type | Description |
|---|---|---|
steps |
string[] |
Step order. Defaults to the stack's route order. |
formatTitle |
(step, total) => string |
Default title when the screen has no options.title. step starts at 1. |
onBack |
() => void |
Back button action. Defaults to goBack(); on the first step, same as close. |
onClose |
() => void |
Close button action. Defaults to leaving the step stack (getParent().goBack()). |
showBack |
boolean |
Show the back button. Default true. |
showClose |
boolean |
Show the close button. Default true. |
right |
ReactNode |
Extra content before the close button (e.g. a help button). |
backIcon |
ReactNode |
Replaces the back icon. |
closeIcon |
ReactNode |
Replaces the close icon. |
progressBar |
boolean |
Show the progress bar. Default true. |
progressBarStyle |
{ height?, color?, backgroundColor? } |
Progress bar look. |
style |
ViewStyle |
Header container style. |
titleStyle |
TextStyle |
Title style. |
iconBackColor |
string |
Default back icon color. |
iconCloseColor |
string |
Default close icon color. |
getStep(routeName, steps) is exported too, if you want to build your own header: it returns { index, total, progress }.
1.0 removes StepNavigationProvider, useStepNavigation and createStepNavigation. To migrate:
- Remove
<StepNavigationProvider>andonStateChangefrom yourNavigationContainer. - Replace
createStepNavigation()withcreateNativeStackNavigator()(orcreateStackNavigator()), and passscreenOptions={{ header: (p) => <StepHeader {...p} /> }}. - Move these props from
Step.NavigatortoStepHeader:progressBarStyle,headerStyle(nowstyle),titleStyle,iconBackColor,iconCloseColor. - Replace
closeRoutewithonClose={() => navigation.navigate('Route')}. - Replace
titlewithoptions.title. - On
Step.Screen, replaceheader={false}withoptions={{ headerShown: false }}.
example/ is an Expo Router app that uses src/ directly:
cd example && npm install && npm startMIT 📜
