Skip to content

Commit d99d0ef

Browse files
committed
Add a deprecations section to the upgrade guide
1 parent 95cf437 commit d99d0ef

File tree

1 file changed

+86
-61
lines changed

1 file changed

+86
-61
lines changed

versioned_docs/version-6.x/upgrading-from-5.x.md

Lines changed: 86 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -8,95 +8,128 @@ React Navigation 6 keeps the same API as React Navigation 5, however there are s
88

99
This guide lists all the changes and new features that you need to keep in mind when upgrading.
1010

11-
## Table of breaking changes
11+
### Minimum Requirements
1212

13-
The upgrade guide includes both new features as well as breaking changes across all packages. The table below is for your convenience to quickly find the list of all the breaking changes.
13+
React Navigation 6 requires newer versions of following libraries:
1414

15-
- General Changes: These changes affect all React Navigation users.
15+
- `react-native-safe-area-context` >= 3.0.0
16+
- `react-native-screens` >= 2.15.0
17+
- `react-native-tab-view` >= 3.0.0
18+
- `react-native` >= 0.63.0
19+
- `expo` - 40+ (if you use Expo)
20+
21+
To upgrade `react-native-safe-area-context` and `react-native-screens` to the latest supported versions, do the following:
22+
23+
For Expo managed projects:
24+
25+
```sh
26+
expo install react-native-safe-area-context react-native-screens
27+
```
28+
29+
For bare React Native projects:
30+
31+
```sh npm2yarn
32+
npm install react-native-safe-area-context react-native-screens
33+
```
34+
35+
Note that latest versions of `react-native-screens` are now enabled by default. So you will need to disable it manually if you can't have it enabled for some reason.
36+
37+
## Table of breaking changes and deprecations
38+
39+
The upgrade guide includes both new features as well as breaking changes across all packages. The table below is for your convenience to quickly find the list of all the breaking changes and deprecations.
40+
41+
### Breaking changes
42+
43+
The following breaking changes may break your app if you're using the related APIs. So you may need to change your code when upgrading.
44+
45+
- General changes: These changes affect all React Navigation users.
1646

17-
- [Older versions of some libraries are no longer supported](#older-versions-of-some-libraries-are-no-longer-supported)
1847
- [Params are now overwritten on navigation instead of merging](#params-are-now-overwritten-on-navigation-instead-of-merging)
1948
- [Dropped `dangerously` from `dangerouslyGetParent` and `dangerouslyGetState`](#dropped-dangerously-from-dangerouslygetparent-and-dangerouslygetstate)
2049
- [No more `state` property on the `route` prop](#no-more-state-property-on-the-route-prop)
2150
- [Linking configuration is now stricter](#linking-configuration-is-now-stricter)
2251
- [Dropped useLinking hook](#dropped-uselinking-hook)
52+
- [The default value for `backBehavior` is now `firstRoute` for tabs and drawer](#the-default-value-for-backbehavior-is-now-firstroute-for-tabs-and-drawer)
2353
- [Stricter types for TypeScript](#stricter-types-for-typescript)
2454

2555
- Stack Navigator: These changes affect users of `@react-navigation/stack` package.
2656

27-
- [`keyboardHandlingEnabled` is moved to options](#keyboardhandlingenabled-is-moved-to-options)
28-
- [`mode="modal"` is removed in favor of `presentation: 'modal'`](#modemodal-is-removed-in-favor-of-presentation-modal)
29-
- [`headerMode="none"` is removed in favor of `headerShown: false`](#headermodenone-is-removed-in-favor-of-headershown-false)
30-
- [`headerMode` is moved to options](#headermode-is-moved-to-options)
3157
- [Custom header now uses `'headerMode: screen'` by default](#custom-header-now-uses-headermode-screen-by-default)
32-
- [Props passed to custom header are streamlined](#props-passed-to-custom-header-are-streamlined)
3358
- [Header now uses flexbox](#header-now-uses-flexbox)
59+
- [Props passed to custom header are streamlined](#props-passed-to-custom-header-are-streamlined)
3460
- [The `gestureResponseDistance` option is now a number instead of an object](#the-gestureresponsedistance-option-is-now-a-number-instead-of-an-object)
3561
- [Some exports are now moved to the element library](#some-exports-are-now-moved-to-the-element-library)
3662

3763
- Bottom Tab Navigator: These changes affect users of `@react-navigation/bottom-tabs` package.
3864

3965
- [A header is shown by default in tab screens](#a-header-is-shown-by-default-in-tab-screens)
40-
- [The `tabBarOptions` prop is removed in favor of more flexible `options` for bottom tabs](#the-tabbaroptions-prop-is-removed-in-favor-of-more-flexible-options-for-bottom-tabs)
41-
- [The `tabBarVisible` option is no longer present](#the-tabbarvisible-option-is-no-longer-present)
42-
- [The `lazy` prop is moved to `lazy` option for per-screen configuration for bottom tabs](#the-lazy-prop-is-moved-to-lazy-option-for-per-screen-configuration-for-bottom-tabs)
43-
- [The default value for `backBehavior` is now `firstRoute` for bottom tabs](#the-default-value-for-backbehavior-is-now-firstroute-for-bottom-tabs)
4466

4567
- Material Top Tab Navigator: These changes affect users of `@react-navigation/material-top-tabs` package.
4668

4769
- [Material Top Tabs now uses `ViewPager` instead of Reanimated and Gesture Handler](#drawer-now-uses-viewpager-instead-of-reanimated-and-gesture-handler)
48-
- [The `tabBarOptions` prop is removed in favor of more flexible `options` for material top tabs](#the-tabbaroptions-prop-is-removed-in-favor-of-more-flexible-options-for-material-top-tabs)
49-
- [The `lazy` prop is moved to `lazy` option for per-screen configuration for material top tabs](#the-lazy-prop-is-moved-to-lazy-option-for-per-screen-configuration-for-material-top-tabs)
50-
- [The `lazyPlaceholder` prop is moved to `lazyPlaceholder` option for per-screen configuration for material top tabs](#the-lazyplaceholder-prop-is-moved-to-lazyplaceholder-option-for-per-screen-configuration-for-material-top-tabs)
51-
- [The default value for backBehavior is now firstRoute for material top tabs](#the-default-value-for-backbehavior-is-now-firstroute-for-material-top-tabs)
5270

5371
- Material Bottom Tab Navigator: These changes affect users of `@react-navigation/material-bottom-tabs` package.
5472

5573
- [Material Bottom Tabs now uses `react-native-safe-area-context` to apply safe area insets](#material-bottom-tabs-now-uses-react-native-safe-area-context-to-apply-safe-area-insets)
56-
- [The default value for `backBehavior` is now `firstRoute` for material bottom tabs](#the-default-value-for-backbehavior-is-now-firstroute-for-material-bottom-tabs)
5774

5875
- Drawer Navigator: These changes affect users of `@react-navigation/drawer` package.
5976

6077
- [A header is shown by default in drawer screens](#a-header-is-shown-by-default-in-drawer-screens)
6178
- [Slide animation is now default on iOS](#slide-animation-is-now-default-on-ios)
6279
- [Drawer status is now a string instead of a boolean](#drawer-status-is-now-a-string-instead-of-a-boolean)
6380
- [Drawer no longer emits `drawerOpen` and `drawerClose` events](#drawer-no-longer-emits-draweropen-and-drawerclose-events)
64-
- [The `drawerContentOptions` prop is removed in favor of more flexible `options` for drawer](#the-drawercontentoptions-prop-is-now-more-flexible-by-moving-to-options-for-drawer)
65-
- [The `lazy` prop is moved to `lazy` option for per-screen configuration for drawer](#the-lazy-prop-is-moved-to-lazy-option-for-per-screen-configuration-for-bottom-tabs)
66-
- [The default value for `backBehavior` is now `firstRoute` for drawer](#the-default-value-for-backbehavior-is-now-firstroute-for-drawer)
6781

68-
## General changes
82+
### Deprecations
6983

70-
These following changes are in the core library. You'll need to address this changes when upgrading the `@react-navigation/native` package.
84+
The following changes will show deprecation warnings if you're using the related APIs, but your code will continue to work and may be updated at a later date.
7185

72-
To install the 6.x version of `@react-navigation/native`, run:
86+
- Stack Navigator: These changes affect users of `@react-navigation/stack` package.
7387

74-
```sh npm2yarn
75-
npm install @react-navigation/native
76-
```
88+
- [`headerMode="none"` is removed in favor of `headerShown: false`](#headermodenone-is-removed-in-favor-of-headershown-false)
89+
- [`headerMode` is moved to options](#headermode-is-moved-to-options)
90+
- [`mode="modal"` is removed in favor of `presentation: 'modal'`](#modemodal-is-removed-in-favor-of-presentation-modal)
91+
- [`keyboardHandlingEnabled` is moved to options](#keyboardhandlingenabled-is-moved-to-options)
7792

78-
### Older versions of some libraries are no longer supported
93+
- Bottom Tab Navigator: These changes affect users of `@react-navigation/bottom-tabs` package.
7994

80-
React Navigation now requires newer versions of following libraries:
95+
- [The `tabBarOptions` prop is removed in favor of more flexible `options` for bottom tabs](#the-tabbaroptions-prop-is-removed-in-favor-of-more-flexible-options-for-bottom-tabs)
96+
- [The `tabBarVisible` option is no longer present](#the-tabbarvisible-option-is-no-longer-present)
97+
- [The `lazy` prop is moved to `lazy` option for per-screen configuration for bottom tabs](#the-lazy-prop-is-moved-to-lazy-option-for-per-screen-configuration-for-bottom-tabs)
8198

82-
- `react-native-safe-area-context` >= 3.0.0
83-
- `react-native-screens` >= 2.15.0
84-
- `react-native-tab-view` >= 3.0.0
85-
- `react-native` >= 0.63.0
86-
- `expo` - 40+ (if you use Expo)
99+
- Material Top Tab Navigator: These changes affect users of `@react-navigation/material-top-tabs` package.
87100

88-
To upgrade `react-native-safe-area-context` and `react-native-screens` to the latest supported versions, do the following:
101+
- [The `tabBarOptions` prop is removed in favor of more flexible `options` for material top tabs](#the-tabbaroptions-prop-is-removed-in-favor-of-more-flexible-options-for-material-top-tabs)
102+
- [The `lazy` prop is moved to `lazy` option for per-screen configuration for material top tabs](#the-lazy-prop-is-moved-to-lazy-option-for-per-screen-configuration-for-material-top-tabs)
103+
- [The `lazyPlaceholder` prop is moved to `lazyPlaceholder` option for per-screen configuration for material top tabs](#the-lazyplaceholder-prop-is-moved-to-lazyplaceholder-option-for-per-screen-configuration-for-material-top-tabs)
89104

90-
For Expo managed projects:
105+
- Drawer Navigator: These changes affect users of `@react-navigation/drawer` package.
91106

92-
```sh
93-
expo install react-native-safe-area-context react-native-screens
94-
```
107+
- [The `drawerContentOptions` prop is removed in favor of more flexible `options` for drawer](#the-drawercontentoptions-prop-is-now-more-flexible-by-moving-to-options-for-drawer)
108+
- [The `lazy` prop is moved to `lazy` option for per-screen configuration for drawer](#the-lazy-prop-is-moved-to-lazy-option-for-per-screen-configuration-for-bottom-tabs)
95109

96-
For bare React Native projects:
110+
## Note on mixing React Navigation 5 and React Navigation 6 packages
111+
112+
While we don't recommend doing it, it's possible to mix `@react-navigation/xxx` packages from the `6.x.x` and `5.x.x` version ranges to make upgrades easier.
113+
114+
However, there are a few things you need to keep in mind:
115+
116+
- If you're using `@react-navigation/[email protected]` and navigators with `6.x.x` version, it will work in 2 conditions:
117+
118+
- You need to have latest `5.x.x` version of `@react-navigation/native` package installed.
119+
- The deprecated APIs in `6.x.x` versions of the navigators will not work at all, you will need to use the new APIs instead.
120+
- The breaking changes from the "General changes" section won't be applicable.
121+
122+
- If you're using `@react-navigation/[email protected]` and navigators with `5.x.x` version, you need to pay attention to the breaking changes under "General changes" section. `backBehavior`
123+
- If you use TypeScript, you may encounter type errors when using mixing `5.x.x` and `6.x.x`. We suggest ignoring those errors until you can upgrade your packages.
124+
125+
## General changes
126+
127+
These following changes are in the core library. You'll need to address this changes when upgrading the `@react-navigation/native` package.
128+
129+
To install the 6.x version of `@react-navigation/native`, run:
97130

98131
```sh npm2yarn
99-
npm install react-native-safe-area-context react-native-screens
132+
npm install @react-navigation/native
100133
```
101134

102135
### Params are now overwritten on navigation instead of merging
@@ -258,6 +291,12 @@ See docs for [`NavigationContainer`](navigation-container.md#ref) and [Navigatin
258291

259292
Earlier, `useNavigation`, `Link`, `useLinkProps` etc. could only be used inside screens. But now it's possible to use them in any component that's a child of [`NavigationContainer`](navigation-container.md).
260293

294+
### The default value for `backBehavior` is now `firstRoute` for tabs and drawer
295+
296+
Returning to first route after pressing back seems more common in apps. To match this behavior, the tab navigators such as bottom tabs, material top taps, material bottom tabs etc., as well as drawer navigator now use `firstRoute` for the `backBehavior` prop. To preserve old behavior, you can pass `backBehavior="history"` prop to the navigators.
297+
298+
If you have your own custom navigator using `TabRouter` or `DrawerRouter`, it will also be affected by this change unless you have specified a `backbehavior`.
299+
261300
### Stricter types for TypeScript
262301

263302
The type definitions are not stricter, which makes it easier to catch errors earlier by minimizing unsafe types. For example, `useNavigation` now shows a type error if you don't specify a type.
@@ -370,7 +409,9 @@ If you have a custom header, you may need to adjust it to use the new props.
370409
371410
### Header now uses flexbox
372411
373-
The header elements were rendered using absolute positioning which didn't work well in certain situations. We now use flexbox for header elements which should work better. If you have code which relied on the absolute positioning, you'll need to change it.
412+
The header elements were rendered using absolute positioning which didn't work well in certain situations. We now use flexbox for header elements which should work better.
413+
414+
This probably doesn't change anything for you, but if you have code which relied on the absolute positioning, you may need to change it.
374415
375416
### The `gestureResponseDistance` option is now a number instead of an object
376417
@@ -407,11 +448,11 @@ To install the 6.x version of `@react-navigation/native-stack`, run:
407448
npm install @react-navigation/native-stack
408449
```
409450

410-
### Breaking changes
451+
### Breaking changes from `react-native-screens/native-stack`
411452

412453
If you were importing `createNativeStackNavigator` from `react-native-screens/native-stack`, you need to keep the following changes in mind when migrating to `@react-navigation/native-stack` package:
413454

414-
#### Options
455+
#### Options of Native Stack
415456

416457
- `backButtonInCustomView` option is removed, it's now automatically set when necessary
417458
- `headerCenter` option is removed, the `headerLeft`, `headerRight` and `headerTitle` options now work like they do in [Stack Navigator](stack-navigator.md)
@@ -430,7 +471,7 @@ If you were importing `createNativeStackNavigator` from `react-native-screens/na
430471
431472
The `appear` and `disappear` events have been removed in favor of `transitionStart` and `transitionEnd` events with `e.data.closing` indicating whether the screen is being opened or closed.
432473
433-
### Native stack now works on web
474+
### Native Stack now works on web
434475
435476
Previously, `native-stack` could only be used on Android & iOS. But we also added basic web support so that you can write cross-platform apps without having to change your code.
436477
@@ -485,10 +526,6 @@ Since the the tab bar now supports a `tabBarStyle` option, we have removed the `
485526
486527
The `lazy` prop now can be configured per screen instead of for the whole navigator. So it's moved to `options` from props. To keep previous behavior, you can specify it in `screenOptions` to apply it to all screens.
487528

488-
### The default value for `backBehavior` is now `firstRoute` for bottom tabs
489-
490-
Returning to first route after pressing back seems more common in apps. To match this behavior, drawer now uses `firstRoute` for the `backBehavior` prop. To preserve old behavior, you can pass `backBehavior="history"` prop to the bottom tab navigator.
491-
492529
### New `tabBarBackground` option to specify custom backgrounds
493530

494531
The new `tabBarBackground` option is useful to add custom backgrounds to the tab bar such as images, gradients, blur views etc. without having to wrap the `TabBar` manually.
@@ -558,10 +595,6 @@ Similar to bottom tabs, the `lazy` prop is now moved to `options` for material t
558595
559596
The `lazyPlaceholder` prop is now moved to `options` for material top tabs so you can configure a placeholder in each screen's options.
560597

561-
### The default value for `backBehavior` is now `firstRoute` for material top tabs
562-
563-
Similar to bottom tabs, material top tabs now uses `firstRoute` for the `backBehavior` prop as well.
564-
565598
## Material Bottom Tab Navigator
566599

567600
The following changes are in the `@react-navigation/material-bottom-tabs` package.
@@ -576,10 +609,6 @@ npm install @react-navigation/material-bottom-tabs
576609

577610
It's now necessary to install the `react-native-safe-area-context` package when using `@react-navigation/material-bottom-tab`, if you didn't have it already.
578611

579-
### The default value for `backBehavior` is now `firstRoute` for material bottom tabs
580-
581-
Similar to bottom tabs, material bottom tabs now uses `firstRoute` for the `backBehavior` prop as well.
582-
583612
## Drawer Navigator
584613

585614
The following changes are in the `@react-navigation/drawer` package.
@@ -648,10 +677,6 @@ The old options will still keep working with a deprecation warning. To avoid the
648677

649678
Similar to bottom tabs, the `lazy` prop is now moved to `options` for drawer.
650679

651-
### The default value for `backBehavior` is now `firstRoute` for drawer
652-
653-
Similar to bottom tabs, drawer now uses `firstRoute` for the `backBehavior` prop as well.
654-
655680
## Elements Library
656681

657682
We have a new package which contains various UI elements related to navigation, such as a `Header` component. This means that we can now use these components in all navigators. You can also install the library to import components such as `Header` to use in any navigator:

0 commit comments

Comments
 (0)