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: blog/2021-03-12-react-navigation-6.0-next.md
+2-2Lines changed: 2 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -27,10 +27,10 @@ We'll share few highlights of the release in this blog post. If you're looking f
27
27
28
28
## Try it out
29
29
30
-
The new versions are published under `next` tag on [npm](https://npmjs.org). So if you'd like to try it out, add `@next` to the package, you're installing. For example:
30
+
If you'd like to try it out, add `@^6.x` to the package, you're installing. For example:
@@ -6,7 +6,64 @@ sidebar_label: Upgrading from 5.x
6
6
7
7
React Navigation 6 keeps the same API as React Navigation 5, however there are some breaking changes to make the API more consistent, more flexible and less confusing.
8
8
9
-
This guide lists all the changes that you need to keep in mind when upgrading.
9
+
This guide lists all the changes and new features that you need to keep in mind when upgrading.
10
+
11
+
## Table of breaking changes
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.
14
+
15
+
- General Changes: These changes affect all React Navigation users.
16
+
17
+
-[Older versions of some libraries are no longer supported](#older-versions-of-some-libraries-are-no-longer-supported)
18
+
-[Params are now overwritten on navigation instead of merging](#params-are-now-overwritten-on-navigation-instead-of-merging)
19
+
-[Dropped `dangerously` from `dangerouslyGetParent` and `dangerouslyGetState`](#dropped-dangerously-from-dangerouslygetparent-and-dangerouslygetstate)
20
+
-[No more `state` property on the `route` prop](#no-more-state-property-on-the-route-prop)
21
+
-[Linking configuration is now stricter](#linking-configuration-is-now-stricter)
-[Stricter types for TypeScript](#stricter-types-for-typescript)
24
+
25
+
- Stack Navigator: These changes affect users of `@react-navigation/stack` package.
26
+
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
+
-[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
+
-[Header now uses flexbox](#header-now-uses-flexbox)
34
+
-[The `gestureResponseDistance` option is now a number instead of an object](#the-gestureresponsedistance-option-is-now-a-number-instead-of-an-object)
35
+
-[Some exports are now moved to the element library](#some-exports-are-now-moved-to-the-element-library)
36
+
37
+
- Bottom Tab Navigator: These changes affect users of `@react-navigation/bottom-tabs` package.
38
+
39
+
-[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
+
45
+
- Material Top Tab Navigator: These changes affect users of `@react-navigation/material-top-tabs` package.
46
+
47
+
-[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
+
53
+
- Material Bottom Tab Navigator: These changes affect users of `@react-navigation/material-bottom-tabs` package.
54
+
55
+
-[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
+
58
+
- Drawer Navigator: These changes affect users of `@react-navigation/drawer` package.
59
+
60
+
-[A header is shown by default in drawer screens](#a-header-is-shown-by-default-in-drawer-screens)
61
+
-[Slide animation is now default on iOS](#slide-animation-is-now-default-on-ios)
62
+
-[Drawer status is now a string instead of a boolean](#drawer-status-is-now-a-string-instead-of-a-boolean)
63
+
-[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)
10
67
11
68
## General changes
12
69
@@ -183,7 +240,13 @@ For example, you can use it for a bunch of regular screen and a bunch of modal s
183
240
</Stack.Navigator>
184
241
```
185
242
186
-
See [`Group``](group.md) docs for more details.
243
+
See [`Group`](group.md) docs for more details.
244
+
245
+
### New `screenListeners` prop for navigators similar to `screenOptions`
246
+
247
+
It's now possible to add listeners for all of the screens in a navigator by using the `screenListeners`prop. This can be useful to listen to things like `tabPress`for all screens, `state` change at the navigator level etc.
248
+
249
+
See docs for [Navigation Events](navigation-events.md#screenlisteners-prop-on-the-navigator) for more details.
187
250
188
251
### New hook and helper for creating container ref
189
252
@@ -197,7 +260,9 @@ Earlier, `useNavigation`, `Link`, `useLinkProps` etc. could only be used inside
197
260
198
261
### Stricter types for TypeScript
199
262
200
-
The type definitions are not stricter, which makes it easier to catch errors earlier by minimizing unsafe types. For example, `useNavigation` now throws an error if you don't specify a type. You can handle this by annotating it, or for an easier way, specify a type for root navigator which will be used for all usage of`useNavigation`.
263
+
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.
264
+
265
+
You can handle this by [annotating it](typescript.md#annotating-usenavigation), or for an easier way, [specify a type for root navigator](typescript.md#specifying-default-types-for-usenavigation-link-ref-etc) which will be used for all usage of `useNavigation`.
201
266
202
267
### Ability to specify a type for root navigator when using TypeScript
203
268
@@ -243,15 +308,19 @@ Previously, `keyboardHandlingEnabled` was a prop on the navigator, but now it ne
243
308
244
309
Now there is a new`presentation` option which allows you to customize whether a screen is a modal or not on a per screen basis.
245
310
246
-
In addition, to match the default behavior of iOS, now `presentation: 'modal'` shows the new presentation style modal introduced in iOS 13. It also adjusts things like status bar height in the header automatically that you had to do manually before.
311
+
In addition, to match the default behavior of iOS, now `presentation: 'modal'` shows the newpresentation style modal introduced in iOS 13. It also adjusts things like status bar height in the header automatically that you had to do manually before.In addition, the color of the statusbar content is automatically managed when the screen animates.
247
312
248
313
Previously Android didn't have any special animation for modals. But now there's a slide from bottom animation instead of the default animation.
249
314
250
315
If you don't want to use the new animations, you can change it to your liking using the [animation related options](stack-navigator.md#animations). To use the iOS modal animation from React Navigation 5, use `TransitionPresets.ModalSlideFromBottomIOS`.
251
316
252
317
In addition, a new `presentation: 'transparentModal'` option to make it easier to build transparent modals. See [transparent modals](stack-navigator.md#transparent-modals) docs for more details.
253
318
254
-
This also makes it possible to mix regular screens with modal screens in the same stack, since these options don't need to be applied to the whole screen anymore.
319
+
### Better support for mixing different types of animations in a single stack
320
+
321
+
Previously, it was sometimes necessary to nest 2 different stack navigators for certain animations, for example: when we wanted to use modal presentation style and regular styles.
322
+
323
+
It is now possible to mix regular screens with modal screens in the same stack, since these options don't need to be applied to the whole screen anymore.
255
324
256
325
### `headerMode="none"` is removed in favor of`headerShown: false`
257
326
@@ -279,6 +348,14 @@ Previously, `headerMode` was a prop on the navigator, but now it needs to be spe
279
348
280
349
The `headerMode` option supports 2 values: `screen` and `float`.
281
350
351
+
### Header is now taller in modals on iOS
352
+
353
+
The header is now 56dp tall in modals to match the native iOS style. If you are using the [`useHeaderHeight`](elements.md#use-header-height) hook to get the height of the header, then you won't need to change any code.
354
+
355
+
### The header height from hidden header is now ignored
356
+
357
+
Previously, the [`useHeaderHeight`](elements.md#use-header-height) hook returned `0`if the header was hidden in a Stack Navigator. Now it returns the height of the closes visible header instead.
358
+
282
359
### Custom header now uses 'headerMode: screen' by default
283
360
284
361
Previously it was necessary to specify `headerMode='screen'` or a custom animation manually when using a custom header. Even though this was mentioned in the docs, it has been tripped up many people.
@@ -299,6 +376,14 @@ The header elements were rendered using absolute positioning which didn't work w
299
376
300
377
Previously, the [`gestureResponseDistance`](stack-navigator.md#gestureresponsedistance) option took an object with `horizontal` and `vertical` properties. Now it takes a number which will be used as the horizontal or vertical value based on the [`gestureDirection`](stack-navigator.md#gesturedirection) option.
301
378
379
+
### The two finger back gesture on trackpads in iPad is now supported
380
+
381
+
On iPad, it's possible to use two fingers to perform the back gesture in native apps. It's now also possible in Stack Navigator.
382
+
383
+
### Fix accessibility on Web when `react-native-screens` wasn't enabled
384
+
385
+
Previously, unfocused screens were still accessible on Web even if`react-native-screens` was disabled. This is no longer the case. Note that this only works when animations are not enabled (this is the default on Web). Otherwise, you'd need to enable `react-native-screens` to make it work if you had it disabled.
386
+
302
387
### Some exports are now moved to the element library
303
388
304
389
The following exports now live in the elements library since they are no longer specific to the stack navigator:
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
+
327
414
#### Options
328
415
329
416
-`backButtonInCustomView` option is removed, it's now automatically set when necessary
@@ -367,7 +454,7 @@ To keep the previous behavior, you can use `headerShown: false` in `screenOption
367
454
368
455
Previously the tab bar in bottom tabs showed an empty area when no icon was specified. Now it shows a question mark to make it more obvious that the icon is missing.
369
456
370
-
### The `tabBarOptions` prop is now more flexible by moving to`options`for bottom tabs
457
+
### The `tabBarOptions` prop is removed in favor of more flexible`options`for bottom tabs
371
458
372
459
The `tabBarOptions` prop was removed and the options from there were moved to screen's `options` instead. This makes them configurable on a per screen basis.
373
460
@@ -388,7 +475,7 @@ The list of the options and their new name are follows:
388
475
389
476
The `adaptive` option is removed since you can already disable the automatic label positioning by specifying a `tabBarLabelPosition`.
390
477
391
-
To keep the same behavior as before, you can specify these in `screenOptions`.
478
+
The old options will still keep working with a deprecation warning. To avoid the deprecation warning, move these to `screenOptions`.
392
479
393
480
### The `tabBarVisible` option is no longer present
394
481
@@ -432,13 +519,13 @@ For bare React Native projects:
432
519
npm install react-native-pager-view
433
520
```
434
521
435
-
### It now uses `ViewPager` instead of Reanimated and Gesture Handler
522
+
### Material Top Tabs now uses `ViewPager` instead of Reanimated and Gesture Handler
436
523
437
524
The `react-native-tab-view` dependency is upgraded to the latest version (3.x) which now uses [`react-native-pager-view`](https://github.com/callstack/react-native-pager-view) instead of Reanimated and Gesture Handler. This will provide a native UX and also improve the performance.
438
525
439
526
See [release notes for`react-native-tab-view`](https://github.com/satya164/react-native-tab-view/releases/tag/v3.0.0) for more details.
440
527
441
-
### The `tabBarOptions` prop is now more flexible by moving to`options`for material top tabs
528
+
### The `tabBarOptions` prop is removed in favor of more flexible`options`for material top tabs
442
529
443
530
Similar to bottom tabs, the `tabBarOptions` prop was removed and the options from there were moved to screen's `options` instead.
444
531
@@ -461,7 +548,7 @@ The list of the options and their new name are follows:
It's also necessary to install the `react-native-safe-area-context` package when using `@react-navigation/material-bottom-tab`, if you didn't have it already:
575
+
### Material Bottom Tabs now uses `react-native-safe-area-context` to apply safe area insets
576
+
577
+
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.
489
578
490
579
### The default value for`backBehavior` is now `firstRoute`for material bottom tabs
491
580
@@ -553,7 +642,7 @@ The following options have been moved and renamed:
553
642
-`edgeWidth`->`swipeEdgeWidth`
554
643
-`minSwipeDistance`->`swipeMinDistance`
555
644
556
-
To keep the same behavior as before, you can specify these in`screenOptions`.
645
+
The old options will still keep working with a deprecation warning. To avoid the deprecation warning, move these to`screenOptions`.
557
646
558
647
### The `lazy` prop is moved to `lazy` option for per-screen configuration for drawer
0 commit comments