You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: versioned_docs/version-6.x/upgrading-from-5.x.md
+86-61Lines changed: 86 additions & 61 deletions
Original file line number
Diff line number
Diff line change
@@ -8,95 +8,128 @@ React Navigation 6 keeps the same API as React Navigation 5, however there are s
8
8
9
9
This guide lists all the changes and new features that you need to keep in mind when upgrading.
10
10
11
-
##Table of breaking changes
11
+
### Minimum Requirements
12
12
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:
14
14
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:
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.
16
46
17
-
-[Older versions of some libraries are no longer supported](#older-versions-of-some-libraries-are-no-longer-supported)
18
47
-[Params are now overwritten on navigation instead of merging](#params-are-now-overwritten-on-navigation-instead-of-merging)
19
48
-[Dropped `dangerously` from `dangerouslyGetParent` and `dangerouslyGetState`](#dropped-dangerously-from-dangerouslygetparent-and-dangerouslygetstate)
20
49
-[No more `state` property on the `route` prop](#no-more-state-property-on-the-route-prop)
21
50
-[Linking configuration is now stricter](#linking-configuration-is-now-stricter)
-[The default value for `backBehavior` is now `firstRoute` for tabs and drawer](#the-default-value-for-backbehavior-is-now-firstroute-for-tabs-and-drawer)
23
53
-[Stricter types for TypeScript](#stricter-types-for-typescript)
24
54
25
55
- Stack Navigator: These changes affect users of `@react-navigation/stack` package.
26
56
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)
31
57
-[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)
33
58
-[Header now uses flexbox](#header-now-uses-flexbox)
59
+
-[Props passed to custom header are streamlined](#props-passed-to-custom-header-are-streamlined)
34
60
-[The `gestureResponseDistance` option is now a number instead of an object](#the-gestureresponsedistance-option-is-now-a-number-instead-of-an-object)
35
61
-[Some exports are now moved to the element library](#some-exports-are-now-moved-to-the-element-library)
36
62
37
63
- Bottom Tab Navigator: These changes affect users of `@react-navigation/bottom-tabs` package.
38
64
39
65
-[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)
44
66
45
67
- Material Top Tab Navigator: These changes affect users of `@react-navigation/material-top-tabs` package.
46
68
47
69
-[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)
52
70
53
71
- Material Bottom Tab Navigator: These changes affect users of `@react-navigation/material-bottom-tabs` package.
54
72
55
73
-[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)
57
74
58
75
- Drawer Navigator: These changes affect users of `@react-navigation/drawer` package.
59
76
60
77
-[A header is shown by default in drawer screens](#a-header-is-shown-by-default-in-drawer-screens)
61
78
-[Slide animation is now default on iOS](#slide-animation-is-now-default-on-ios)
62
79
-[Drawer status is now a string instead of a boolean](#drawer-status-is-now-a-string-instead-of-a-boolean)
63
80
-[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)
67
81
68
-
##General changes
82
+
### Deprecations
69
83
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.
71
85
72
-
To install the 6.x version of `@react-navigation/native`, run:
86
+
- Stack Navigator: These changes affect users of `@react-navigation/stack` package.
73
87
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)
77
92
78
-
### Older versions of some libraries are no longer supported
93
+
- Bottom Tab Navigator: These changes affect users of `@react-navigation/bottom-tabs` package.
79
94
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)
81
98
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.
87
100
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)
89
104
90
-
For Expo managed projects:
105
+
- Drawer Navigator: These changes affect users of `@react-navigation/drawer` package.
-[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)
95
109
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:
### Params are now overwritten on navigation instead of merging
@@ -258,6 +291,12 @@ See docs for [`NavigationContainer`](navigation-container.md#ref) and [Navigatin
258
291
259
292
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).
260
293
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 inapps. 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
+
261
300
### Stricter types for TypeScript
262
301
263
302
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.
370
409
371
410
### Header now uses flexbox
372
411
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.
374
415
375
416
### The `gestureResponseDistance` option is now a number instead of an object
376
417
@@ -407,11 +448,11 @@ To install the 6.x version of `@react-navigation/native-stack`, run:
407
448
npm install @react-navigation/native-stack
408
449
```
409
450
410
-
### Breaking changes
451
+
### Breaking changes from `react-native-screens/native-stack`
411
452
412
453
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:
413
454
414
-
#### Options
455
+
#### Optionsof Native Stack
415
456
416
457
-`backButtonInCustomView` option is removed, it's now automatically set when necessary
417
458
- `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
430
471
431
472
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.
432
473
433
-
### Native stack now works on web
474
+
### Native Stack now works on web
434
475
435
476
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.
436
477
@@ -485,10 +526,6 @@ Since the the tab bar now supports a `tabBarStyle` option, we have removed the `
485
526
486
527
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.
487
528
488
-
### The default value for`backBehavior` is now `firstRoute`for bottom tabs
489
-
490
-
Returning to first route after pressing back seems more common inapps. 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
-
492
529
### New `tabBarBackground` option to specify custom backgrounds
493
530
494
531
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
558
595
559
596
The `lazyPlaceholder` prop is now moved to `options` for material top tabs so you can configure a placeholder in each screen's options.
560
597
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
-
565
598
## Material Bottom Tab Navigator
566
599
567
600
The following changes are in the `@react-navigation/material-bottom-tabs`package.
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.
578
611
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
-
583
612
## Drawer Navigator
584
613
585
614
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
648
677
649
678
Similar to bottom tabs, the `lazy` prop is now moved to `options`for drawer.
650
679
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
-
655
680
## Elements Library
656
681
657
682
We have a newpackage 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