Skip to content

Commit fed51a6

Browse files
committed
Document more changes in 8.x
1 parent c9c898d commit fed51a6

13 files changed

Lines changed: 248 additions & 197 deletions
Lines changed: 35 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,59 @@
11
---
22
id: navigation-context
3-
title: NavigationContext
4-
sidebar_label: NavigationContext
3+
title: Navigation context
4+
sidebar_label: Navigation context
55
---
66

7-
import Tabs from '@theme/Tabs';
8-
import TabItem from '@theme/TabItem';
7+
The `NavigationProvider` provides the [navigation object](navigation-object.md) and [route object](route-object.md) to components rendered outside of a screen.
98

10-
`NavigationContext` provides the `navigation` object (same object as the [navigation](navigation-object.md) prop). In fact, [useNavigation](use-navigation.md) uses this context to get the `navigation` prop.
9+
Most of the time, you don't need to use this directly. Screens and various built-in components such as headers are automatically provided with the navigation and route objects.
1110

12-
Most of the time, you won't use `NavigationContext` directly, as the provided `useNavigation` covers most use cases. But just in case you have something else in mind, `NavigationContext` is available for you to use.
11+
## Providing navigation and route
1312

14-
Example:
13+
Use `NavigationProvider` when you already have `navigation` and `route` objects and need to make them available to a component that doesn't normally have access to them:
1514

16-
```js name="Navigation context" snack static2dynamic
17-
import * as React from 'react';
18-
import { View, Text } from 'react-native';
19-
import { Button } from '@react-navigation/elements';
20-
// codeblock-focus-start
21-
import { NavigationContext } from '@react-navigation/native';
22-
// codeblock-focus-end
15+
```js
2316
import {
17+
NavigationProvider,
2418
useNavigation,
25-
createStaticNavigation,
19+
useRoute,
2620
} from '@react-navigation/native';
27-
import { createNativeStackNavigator } from '@react-navigation/native-stack';
28-
29-
function HomeScreen() {
30-
return <SomeComponent />;
31-
}
32-
33-
// codeblock-focus-start
34-
35-
function SomeComponent() {
36-
// We can access navigation object via context
37-
const navigation = React.useContext(NavigationContext);
38-
// codeblock-focus-end
3921

22+
function MyComponent({ navigation, route }) {
4023
return (
41-
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
42-
<Text>Some component inside HomeScreen</Text>
43-
<Button onPress={() => navigation.navigate('Profile')}>
44-
Go to Profile
45-
</Button>
46-
</View>
24+
<NavigationProvider navigation={navigation} route={route}>
25+
<MyButton />
26+
</NavigationProvider>
4727
);
48-
// codeblock-focus-start
4928
}
50-
// codeblock-focus-end
5129

52-
function ProfileScreen() {
30+
function MyButton() {
5331
const navigation = useNavigation();
32+
const route = useRoute();
5433

55-
return (
56-
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
57-
<Button onPress={() => navigation.goBack()}>Go back</Button>
58-
</View>
59-
);
34+
// ...
6035
}
36+
```
6137

62-
const RootStack = createNativeStackNavigator({
63-
initialRouteName: 'Home',
64-
screens: {
65-
Home: HomeScreen,
66-
Profile: ProfileScreen,
67-
},
68-
});
38+
This is useful for components rendered in [custom navigators](custom-navigators.md) that are not under a screen.
6939

70-
const Navigation = createStaticNavigation(RootStack);
40+
## Accessing navigation and route
7141

72-
function App() {
73-
return <Navigation />;
74-
}
42+
For most cases, you should use the [`useNavigation`](use-navigation.md) and [`useRoute`](use-route.md) hooks to access the navigation and route objects. They work in screens rendered in a navigator, or components wrapped in a `NavigationProvider`.
43+
44+
However, if you need access to the contexts directly for any reason, you can use `NavigationContext` and `NavigationRouteContext` to access the navigation and route objects from the immediate parent screen or `NavigationProvider`:
7545

76-
export default App;
46+
```js
47+
import * as React from 'react';
48+
import {
49+
NavigationContext,
50+
NavigationRouteContext,
51+
} from '@react-navigation/native';
52+
53+
function MyComponent() {
54+
const navigation = React.useContext(NavigationContext);
55+
const route = React.useContext(NavigationRouteContext);
56+
57+
// ...
58+
}
7759
```

versioned_docs/version-8.x/bottom-tab-navigator.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1024,7 +1024,7 @@ Supported on iOS 18 and above with `native` implementation. Not supported on tvO
10241024
The minimize behavior for the tab bar. Supported values:
10251025

10261026
- `auto` - resolves to the system default minimize behavior
1027-
- `never` - the tab bar does not minimize
1027+
- `none` - the tab bar does not minimize
10281028
- `onScrollDown` - the tab bar minimizes when scrolling down and expands when scrolling back up
10291029
- `onScrollUp` - the tab bar minimizes when scrolling up and expands when scrolling back down
10301030

versioned_docs/version-8.x/devtools.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ The package exposes the following APIs:
2323

2424
### `useLogger`
2525

26-
This hook provides a logger for React Navigation. It logs the navigation state and actions to the console.
26+
This hook provides a logger for React Navigation. It logs the navigation state, actions, deep links, and events emitted by navigators to the console.
2727

2828
<video playsInline autoPlay muted loop style={{ width: "585px" }}>
2929

versioned_docs/version-8.x/drawer-layout.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,6 @@ Callback which is called when the drawer is closed.
105105

106106
Callback which returns a react element to render as the content of the drawer.
107107

108-
##### `layout`
109-
110-
Object containing the layout of the container. Defaults to the dimensions of the application's window.
111-
112108
##### `drawerPosition`
113109

114110
Position of the drawer on the screen. Defaults to `right` in RTL mode, otherwise `left`.

versioned_docs/version-8.x/drawer-navigator.md

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,10 @@ drawerItemStyle: {
448448
},
449449
```
450450

451+
#### `drawerItemTestID`
452+
453+
ID to locate the drawer item in tests.
454+
451455
#### `drawerLabelStyle`
452456

453457
Style object to apply to the `Text` style inside content section which renders a label.
@@ -657,13 +661,6 @@ Minimum swipe distance threshold that should activate opening the drawer.
657661

658662
Whether the keyboard should be dismissed when the swipe gesture begins. Defaults to `'on-drag'`. Set to `'none'` to disable keyboard handling.
659663

660-
#### `freezeOnBlur`
661-
662-
Boolean indicating whether to prevent inactive screens from re-rendering. Defaults to `false`.
663-
Defaults to `true` when `enableFreeze()` from `react-native-screens` package is run at the top of the application.
664-
665-
Only supported on iOS and Android.
666-
667664
#### `popToTopOnBlur`
668665

669666
Boolean indicating whether any nested stack should be popped to the top of the stack when navigating away from this drawer screen. Defaults to `false`.

versioned_docs/version-8.x/elements.md

Lines changed: 59 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ It receives an object containing following properties:
178178
- `tintColor`: The color of the icon and label.
179179
- `pressColor`: The color of the material ripple (Android >= 5.0 only).
180180
- `pressOpacity`: The opacity of the button when it's pressed (Android < 5.0, and iOS).
181-
- `displayMode`: How the element displays icon and title. Defaults to `default` on iOS and `minimal` on Android. Possible values:
181+
- `displayMode`: How the element displays icon and title. Defaults to `default` on iOS 25 and below, and `minimal` on iOS 26 and above and Android. Possible values:
182182
- `default`: Displays one of the following depending on the available space: previous screen's title, generic title (e.g. 'Back') or no title (only icon).
183183
- `generic`: Displays one of the following depending on the available space: generic title (e.g. 'Back') or no title (only icon). iOS >= 14 only, falls back to "default" on older iOS versions.
184184
- `minimal`: Always displays only the icon without a title.
@@ -373,7 +373,7 @@ Customize the style for the container of the `headerLeft` component, for example
373373

374374
Whether the liquid glass background is visible for the item.
375375

376-
Only supported on iOS 26.0 and later. Older versions of iOS and other platforms never show the background.\
376+
Only supported on iOS 26.0 and later. Older versions of iOS and other platforms never show the background.
377377

378378
Defaults to `true`.
379379

@@ -413,6 +413,35 @@ Note that if you don't want your content to appear under the header, you need to
413413

414414
To get the height of the header, you can use [`HeaderHeightContext`](#headerheightcontext) with [React's Context API](https://react.dev/reference/react/useContext#contextconsumer) or [`useHeaderHeight`](#useheaderheight).
415415

416+
#### `headerBlurEffect`
417+
418+
Blur effect for the transparent header on Web. The `headerTransparent` option needs to be set to `true` for this to work.
419+
420+
Supported values:
421+
422+
- `extraLight`
423+
- `light`
424+
- `regular`
425+
- `prominent`
426+
- `systemUltraThinMaterial`
427+
- `systemThinMaterial`
428+
- `systemMaterial`
429+
- `systemThickMaterial`
430+
- `systemChromeMaterial`
431+
- `systemUltraThinMaterialLight`
432+
- `systemThinMaterialLight`
433+
- `systemMaterialLight`
434+
- `systemThickMaterialLight`
435+
- `systemChromeMaterialLight`
436+
- `dark`
437+
- `systemUltraThinMaterialDark`
438+
- `systemThinMaterialDark`
439+
- `systemMaterialDark`
440+
- `systemThickMaterialDark`
441+
- `systemChromeMaterialDark`
442+
443+
Only supported on Web.
444+
416445
#### `headerBackground`
417446

418447
Function which returns a React Element to render as the background of the header. This is useful for using backgrounds such as an image or a gradient.
@@ -621,17 +650,14 @@ A component used to show the back button header. It's the default for [`headerLe
621650
- `pressColor` - Color for material ripple (Android >= 5.0 only).
622651
- `icon` - Icon to display custom icon in header's back button. See [Custom back icon](#custom-back-icon) section for more details.
623652
- `tintColor` - Tint color for the header.
624-
- `label` - Label text for the button. Usually the title of the previous screen. By default, this is only shown on iOS.
653+
- `label` - Label text for the button. Usually the title of the previous screen. By default, this is only shown on iOS 25 and below.
625654
- `truncatedLabel` - Label text to show when there isn't enough space for the full label.
626-
- `displayMode`: How the back button displays icon and title. Defaults to `default` on iOS and `minimal` on Android. Possible values:
655+
- `displayMode`: How the back button displays icon and title. Defaults to `default` on iOS 25 and below, and `minimal` on iOS 26 and above and Android. Possible values:
627656
- `default`: Displays one of the following depending on the available space: previous screen's title, generic title (e.g. 'Back') or no title (only icon).
628657
- `generic`: Displays one of the following depending on the available space: generic title (e.g. 'Back') or no title (only icon). iOS >= 14 only, falls back to "default" on older iOS versions.
629658
- `minimal`: Always displays only the icon without a title.
630659
- `labelStyle` - Style object for the label.
631660
- `allowFontScaling` - Whether label font should scale to respect Text Size accessibility settings.
632-
- `onLabelLayout` - Callback to trigger when the size of the label changes.
633-
- `screenLayout` - Layout of the screen.
634-
- `titleLayout` - Layout of the title element in the header.
635661
- `canGoBack` - Boolean to indicate whether it's possible to navigate back in stack.
636662
- `accessibilityLabel` - Accessibility label for the button for screen readers.
637663
- `testID` - ID to locate this button in tests.
@@ -702,7 +728,9 @@ A component that renders a button. In addition to [`PlatformPressable`](#platfor
702728
- `plain`
703729
- `filled`
704730
- `color` - Color of the button. Defaults to the [theme](themes.md)'s primary color.
705-
- `children` - Content to render inside the button.
731+
- `icon` - Icon to display before the label. It can be an icon object or a function that returns an icon object or a React element. See [Icons](icons.md) for more details.
732+
- `disabled` - Boolean which controls whether the button is disabled.
733+
- `children` - Content to render inside the button. It must be a string or React element that can be nested inside a `Text` component.
706734

707735
In addition, the button integrates with React Navigation and accepts the same props as [`useLinkProps`](use-link-props.md#options) hook.
708736

@@ -720,6 +748,29 @@ Or as a regular button:
720748
<Button onPress={() => console.log('button pressed')}>Press me</Button>
721749
```
722750

751+
You can use the `icon` prop to show an icon before the label:
752+
753+
```js
754+
<Button
755+
icon={Platform.select({
756+
ios: {
757+
type: 'sfSymbol',
758+
name: 'person',
759+
},
760+
android: {
761+
type: 'materialSymbol',
762+
name: 'person',
763+
},
764+
})}
765+
screen="Profile"
766+
params={{ userId: 'jane' }}
767+
>
768+
Go to Profile
769+
</Button>
770+
```
771+
772+
See [Icons](icons.md) for more details on icons.
773+
723774
### `Label`
724775

725776
The `Label` component is used to render small text. It is used in [Bottom Tab Navigator](bottom-tab-navigator.md) to render the label for each tab.

versioned_docs/version-8.x/material-top-tab-navigator.md

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -163,16 +163,6 @@ Possible values:
163163

164164
Only supported on Android.
165165

166-
#### `initialLayout`
167-
168-
Object containing the initial height and width of the screens. Passing this will improve the initial rendering performance. For most apps, this is a good default:
169-
170-
```js
171-
{
172-
width: Dimensions.get('window').width,
173-
}
174-
```
175-
176166
#### `style`
177167

178168
Style to apply to the tab view container.

versioned_docs/version-8.x/native-stack-navigator.md

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -402,13 +402,6 @@ Boolean indicating whether the navigation bar should be hidden. Defaults to `fal
402402

403403
Only supported on Android.
404404

405-
#### `freezeOnBlur`
406-
407-
Boolean indicating whether to prevent inactive screens from re-rendering. Defaults to `false`.
408-
Defaults to `true` when `enableFreeze()` from `react-native-screens` package is run at the top of the application.
409-
410-
Only supported on iOS and Android.
411-
412405
#### `scrollEdgeEffects`
413406

414407
Configures the scroll edge effect for the _content ScrollView_ (the ScrollView that is present in first descendants chain of the Screen).
@@ -910,7 +903,7 @@ headerRight: () => <MaterialCommunityIcons name="map" color="blue" size={36} />;
910903

911904
Whether the liquid glass background is visible for the item.
912905

913-
Only supported on iOS 26.0 and later. Older versions of iOS and other platforms never show the background.\
906+
Only supported on iOS 26.0 and later. Older versions of iOS and other platforms never show the background.
914907

915908
Defaults to `true`.
916909

versioned_docs/version-8.x/navigation-actions.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,8 @@ The `preload` action allows preloading a screen in the background before navigat
450450

451451
- `name` - _string_ - A destination name of the screen in the current or a parent navigator.
452452
- `params` - _object_ - Params to use for the destination route.
453+
- `options` - Options object containing the following properties:
454+
- `reuse` - _boolean_ - Whether to reuse a matching preloaded or existing route instead of adding a new preloaded route. Defaults to `false`.
453455

454456
```js name="Common actions preload" snack static2dynamic
455457
import * as React from 'react';
@@ -551,7 +553,7 @@ Preloading a screen means that the screen will be rendered in the background. Al
551553
552554
Depending on the navigator, `preload` may work differently:
553555
554-
- In a stack navigator ([stack](stack-navigator.md), [native stack](native-stack-navigator.md)), the screen will be rendered off-screen and animated in when you navigate to it. If [`getId`](screen.md#id) is specified, it'll be used for the navigation to identify the preloaded screen.
556+
- In a stack navigator ([stack](stack-navigator.md), [native stack](native-stack-navigator.md)), the screen will be rendered off-screen and animated in when you navigate to it. If [`getId`](screen.md#id) is specified, it'll be used for the navigation to identify the preloaded screen. When `reuse` is `true`, a matching preloaded or existing route will be reused and its params will be updated.
555557
- In a tab or drawer navigator ([bottom tabs](bottom-tab-navigator.md), [material top tabs](material-top-tab-navigator.md), [drawer](drawer-navigator.md), etc.), the existing screen will be rendered as if `lazy` was set to `false`. Calling `preload` on a screen that is already rendered will not have any effect.
556558

557559
### setParams

0 commit comments

Comments
 (0)