@@ -21,7 +21,124 @@ npm install @react-navigation/elements@next
2121
2222### ` Header `
2323
24- A component that can be used as a header. It accepts the following props:
24+ A component that can be used as a header. This is used by all the navigators by default.
25+
26+ Usage:
27+
28+ ``` js name="React Navigation Elements Header" snack version=7
29+ import * as React from ' react' ;
30+ import { SafeAreaProviderCompat } from ' @react-navigation/elements' ;
31+ import { NavigationContainer } from ' @react-navigation/native' ;
32+ // codeblock-focus-start
33+ import { Header } from ' @react-navigation/elements' ;
34+
35+ function MyHeader () {
36+ return < Header title= " My app" / > ;
37+ }
38+ // codeblock-focus-end
39+
40+ export default function App () {
41+ return (
42+ < NavigationContainer>
43+ < SafeAreaProviderCompat>
44+ < MyHeader / >
45+ < / SafeAreaProviderCompat>
46+ < / NavigationContainer>
47+ );
48+ }
49+ ```
50+
51+ To use the header in a navigator, you can use the ` header ` option in the screen options:
52+
53+ <Tabs groupId =" config " queryString =" config " >
54+ <TabItem value =" static " label =" Static " default >
55+
56+ ``` js name="Header with Native Stack" snack version=7
57+ import * as React from ' react' ;
58+ import { Text , View , Button } from ' react-native' ;
59+ import { createStaticNavigation } from ' @react-navigation/native' ;
60+ import { createNativeStackNavigator } from ' @react-navigation/native-stack' ;
61+ // codeblock-focus-start
62+ import { Header , getHeaderTitle } from ' @react-navigation/elements' ;
63+
64+ // codeblock-focus-end
65+ function HomeScreen () {
66+ return (
67+ < View style= {{ flex: 1 , alignItems: ' center' , justifyContent: ' center' }}>
68+ < Text > Home Screen< / Text >
69+ < / View>
70+ );
71+ }
72+
73+ // codeblock-focus-start
74+ const MyStack = createNativeStackNavigator ({
75+ screenOptions: {
76+ header : ({ options, route }) => (
77+ < Header {... options} title= {getHeaderTitle (options, route .name )} / >
78+ ),
79+ },
80+ screens: {
81+ Home: HomeScreen,
82+ },
83+ });
84+ // codeblock-focus-end
85+
86+ const Navigation = createStaticNavigation (MyStack);
87+
88+ export default function App () {
89+ return < Navigation / > ;
90+ }
91+ ```
92+
93+ </TabItem >
94+ <TabItem value =" dynamic " label =" Dynamic " >
95+
96+ ``` js name="Header with Native Stack" snack version=7
97+ import * as React from ' react' ;
98+ import { Text , View , Button } from ' react-native' ;
99+ import { NavigationContainer } from ' @react-navigation/native' ;
100+ import { createNativeStackNavigator } from ' @react-navigation/native-stack' ;
101+ // codeblock-focus-start
102+ import { Header , getHeaderTitle } from ' @react-navigation/elements' ;
103+
104+ const Stack = createNativeStackNavigator ();
105+
106+ function MyStack () {
107+ return (
108+ < Stack .Navigator
109+ screenOptions= {{
110+ header : ({ options, route }) => (
111+ < Header {... options} title= {getHeaderTitle (options, route .name )} / >
112+ ),
113+ }}
114+ >
115+ < Stack .Screen name= " Home" component= {HomeScreen} / >
116+ < / Stack .Navigator >
117+ );
118+ }
119+ // codeblock-focus-end
120+
121+ function HomeScreen () {
122+ return (
123+ < View style= {{ flex: 1 , alignItems: ' center' , justifyContent: ' center' }}>
124+ < Text > Home Screen< / Text >
125+ < / View>
126+ );
127+ }
128+
129+ export default function App () {
130+ return (
131+ < NavigationContainer>
132+ < MyStack / >
133+ < / NavigationContainer>
134+ );
135+ }
136+ ```
137+
138+ </TabItem >
139+ </Tabs >
140+
141+ It accepts the following props:
25142
26143#### ` headerTitle `
27144
0 commit comments