Skip to content

Commit 8ea6404

Browse files
docs: use native-stack in header-buttons
1 parent 39a3748 commit 8ea6404

File tree

3 files changed

+10
-12
lines changed

3 files changed

+10
-12
lines changed

static/examples/6.x/header-interaction.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as React from 'react';
22
import { Button, Text, Image } from 'react-native';
33
import { NavigationContainer } from '@react-navigation/native';
4-
import { createStackNavigator } from '@react-navigation/stack';
4+
import { createNativeStackNavigator } from '@react-navigation/native-stack';
55

66
function LogoTitle() {
77
return (
@@ -26,7 +26,7 @@ function HomeScreen({ navigation }) {
2626
return <Text>Count: {count}</Text>;
2727
}
2828

29-
const Stack = createStackNavigator();
29+
const Stack = createNativeStackNavigator();
3030

3131
function App() {
3232
return (

static/examples/6.x/simple-header-button.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import * as React from 'react';
22
import { View, Text, Button, Image } from 'react-native';
33
import { NavigationContainer } from '@react-navigation/native';
4-
import { createStackNavigator } from '@react-navigation/stack';
4+
import { createNativeStackNavigator } from '@react-navigation/native-stack';
55

6-
const Stack = createStackNavigator();
6+
const Stack = createNativeStackNavigator();
77

88
function HomeScreen() {
99
return (

versioned_docs/version-6.x/header-buttons.md

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,22 +75,20 @@ function HomeScreen({ navigation }) {
7575

7676
## Customizing the back button
7777

78-
`createStackNavigator` provides the platform-specific defaults for the back button. On iOS this includes a label next to the button, which shows the title of the previous screen when the title fits in the available space, otherwise it says "Back".
78+
`createNativeStackNavigator` provides the platform-specific defaults for the back button. On iOS this includes a label next to the button, which shows the title of the previous screen when the title fits in the available space, otherwise it says "Back".
7979

80-
You can change the label behavior with `headerBackTitle` and `headerTruncatedBackTitle` ([read more](stack-navigator.md#headerbacktitle)).
80+
You can change the label behavior with `headerBackTitle` and style it with `headerBackTitleStyle` ([read more](native-stack-navigator.md#headerbacktitle)).
8181

82-
To customize the back button image, you can use [headerBackImage](stack-navigator.md#headerbackimage).
82+
To customize the back button image, you can use `headerBackImageSource` ([read more](native-stack-navigator.md#headerbackimagesource)).
8383

8484
## Overriding the back button
8585

86-
The back button will be rendered automatically in a stack navigator whenever it is possible for the user to go back from their current screen &mdash; in other words, the back button will be rendered whenever there is more than one screen in the stack.
86+
The back button will be rendered automatically in a native stack navigator whenever it is possible for the user to go back from their current screen &mdash; in other words, the back button will be rendered whenever there is more than one screen in the stack.
8787

88-
Generally, this is what you want. But it's possible that in some circumstances that you want to customize the back button more than you can through the options mentioned above, in which case you can set the `headerLeft` option to a React Element that will be rendered, just as we did with `headerRight`. Alternatively, the `headerLeft` option also accepts a React Component, which can be used, for example, for overriding the onPress behavior of the back button. Read more about this in the [api reference](stack-navigator.md#headerleft).
89-
90-
If you would like to retain the view of back button and only override the `onPress` method, you can import [HeaderBackButton](https://github.com/react-navigation/react-navigation/blob/main/packages/stack/src/views/Header/HeaderBackButton.tsx) from `@react-navigation/stack` and assign that component to the `headerLeft` option.
88+
Generally, this is what you want. But it's possible that in some circumstances that you want to customize the back button more than you can through the options mentioned above, in which case you can set the `headerLeft` option to a React Element that will be rendered, just as we did with `headerRight`. Alternatively, the `headerLeft` option also accepts a React Component, which can be used, for example, for overriding the onPress behavior of the back button. Read more about this in the [api reference](native-stack-navigator.md#headerleft).
9189

9290
## Summary
9391

9492
- You can set buttons in the header through the `headerLeft` and `headerRight` properties in `options`.
95-
- The back button is fully customizable with `headerLeft`, but if you just want to change the title or image, there are other `options` for that &mdash; `headerBackTitle`, `headerTruncatedBackTitle`, and `headerBackImage`.
93+
- The back button is fully customizable with `headerLeft`, but if you just want to change the title or image, there are other `options` for that &mdash; `headerBackTitle`, `headerBackTitleStyle`, and `headerBackImageSource`.
9694
- You can use a callback for the options prop to access `navigation` and `route` objects.

0 commit comments

Comments
 (0)