Header
A customizable navigation header component with support for back buttons, title, and action items.
Header
The Header component provides a consistent navigation bar for your application screens with customizable elements and theming support.
Import
Features
- Customizable Content: Title, back button, and support for custom components
- Right Action Items: Multiple buttons or controls on the right side
- Collapsible Animation: Optional collapsible behavior for scrolling content
- Theming Support: Automatically adapts to light/dark mode
- Custom Styling: Accepts additional Tailwind classes
- Header Icons: Built-in HeaderIcon component for navigation and action buttons
Props
Header Component
Prop | Type | Default | Description |
---|---|---|---|
title | string | — | Text to display as the header title |
showBackButton | boolean | false | Whether to show a back button |
onBackPress | () => void | — | Custom action for the back button |
rightComponents | React.ReactNode[] | [] | Components to display on the right side |
leftComponent | React.ReactNode | — | Custom component for the left side |
middleComponent | React.ReactNode | — | Custom component for the center |
collapsible | boolean | false | Whether the header should animate on scroll |
visible | boolean | true | Controls visibility when collapsible is true |
HeaderIcon Component
Prop | Type | Default | Description |
---|---|---|---|
href | string | — | Navigation link |
icon | IconName | Required | Name of the icon to display |
hasBadge | boolean | false | Whether to show a notification badge |
onPress | Function | — | Custom press handler |
Basic Usage
Usage Examples
Basic Header with Title
Header with Back Button
Header with Right Action Icons
Collapsible Header
Custom Header with Middle Component
Profile Screen Example
E-commerce Header Example
Chat Header Example
Best Practices
Consistent Header Style
Maintain a consistent header style throughout your application:
HeaderIcon Usage
Use HeaderIcon components consistently for action items:
Collapsible Header Management
When using collapsible headers, ensure proper content padding:
Implementation Details
The Header component is built with React Native's View and TouchableOpacity components, utilizing Tailwind CSS for styling. It supports both static and animated behaviors through the use of the Animated API.
For collapsible headers, the component uses Animated.spring and Animated.timing to create smooth translation and opacity animations based on the visible
prop.
The component automatically adapts to the current theme using the useThemeColors
hook, ensuring proper appearance in both light and dark modes.
The HeaderIcon subcomponent provides a standardized way to add action buttons to the header, with built-in support for navigation links via Expo Router and notification badges.
Notes
- When using collapsible headers, remember to add appropriate padding to your scrollable content
- The header uses the z-index to ensure it appears above other content
- For custom header layouts, you can use the leftComponent and middleComponent props
- The HeaderIcon component can be used independently for consistent icon buttons
- Back button behavior defaults to
router.back()
but can be customized with the onBackPress prop