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-7.x/upgrading-from-6.x.md
+247-15
Original file line number
Diff line number
Diff line change
@@ -171,6 +171,43 @@ The `buildHref` method acts the same as the previously returned function. The ne
171
171
172
172
Note that this hook is intended to be primarily used by custom navigators and not by end users. For end users, the `Link` component and `useLinkProps` are the recommended way to navigate.
173
173
174
+
### Custom navigators now require more type information
175
+
176
+
Custom navigators now require more type information to work correctly so that we can provide better type-checking and autocompletion in TypeScript when using the navigator.
Previously, we added a Flipper plugin for React Navigation to make debugging navigation easier. However, it has added significant maintenance overhead for us. The Flipper team hasn't been focused on React Native recently, so the overall experience of using Flipper with React Native has been poor.
@@ -246,7 +283,12 @@ Here is the full list of removed APIs:
246
283
247
284
### `customAnimationOnGesture` is renamed to `animationMatchesGesture`in Native Stack Navigator
248
285
249
-
TODO
286
+
The `customAnimationOnGesture` option in Native Stack Navigator is renamed to `animationMatchesGesture` to better reflect its purpose. If you are using `customAnimationOnGesture`in your project, you can rename it to `animationMatchesGesture`:
### Material Top Tab Navigator no longers requires installing `react-native-tab-view`
252
294
@@ -269,46 +311,236 @@ If you are using `@react-navigation/material-bottom-tabs` in your project, you c
269
311
270
312
### The `tabBarTestID` option is renamed to `tabBarButtonTestID` in Bottom Tab Navigator
271
313
272
-
TODO
314
+
The `tabBarTestID` option in Bottom Tab Navigator is renamed to `tabBarButtonTestID` to better reflect its purpose. If you are using `tabBarTestID` in your project, you can rename it to `tabBarButtonTestID`:
### Drawer Navigator now requires Reanimated 2 or 3 on native platforms
322
+
323
+
Previously, `@react-navigation/drawer` supported both Reanimated 1 and Reanimated 2 APIs with the `useLegacyImplementation` option. This is now no longer supported and the `useLegacyImplementation` option is removed.
324
+
325
+
If you are using Reanimated 1 in your project, you'll need to upgrade to Reanimated 2 or 3 to use `@react-navigation/drawer`.
273
326
274
-
### Drawer Navigator no longer supports Reanimated 1
327
+
If you're using Drawer Navigator on the Web, it'll now use CSS transitions instead ofReanimated for a smaller bundle size.
275
328
276
-
TODO
329
+
### Various UI elements now follow Material Design 3 guidelines
330
+
331
+
Previously, the UI elements in React Navigation such as the header on platforms other than iOS, drawer, material top tabs etc. were following the Material Design 2guidelines. We have now updated them to follow the Material Design 3 guidelines.
277
332
278
333
## New features
279
334
280
335
### Navigators now support a static configuration API
281
336
282
-
TODO
337
+
React Navigation 5 introduced a dynamic API to support more flexible use cases. With React Navigation 7, we are re-introducing a static configuration API:
338
+
339
+
```js
340
+
import { createNativeStackNavigator } from 'react-native-screens/native-stack';
341
+
342
+
const MyStack = createNativeStackNavigator({
343
+
screens: {
344
+
Home: {
345
+
screen: HomeScreen,
346
+
options: {
347
+
title: 'My App',
348
+
},
349
+
},
350
+
Details: {
351
+
screen: DetailsScreen,
352
+
linking: 'details/:id',
353
+
},
354
+
},
355
+
});
356
+
```
357
+
358
+
The static configuration API provides the following benefits:
359
+
360
+
- Simpler type-checking with TypeScript, it's not necessary to specify screens and their params separately.
361
+
- Easier deep linking setup, the linking configuration can be defined next to the screen.
362
+
363
+
It's also possible to mix the static and dynamic configuration APIs. For example, you can use the static configuration APIfor the top-level navigators and the dynamic configuration APIfor the nested navigators where you need more flexibility.
364
+
365
+
:::note
366
+
367
+
The static configuration API doesn't replace the dynamic configuration API. Both APIs are equally supported and you can choose the one that fits your use case better.
368
+
369
+
:::
370
+
371
+
You can see examples for both the static and dynamic configuration APIs in the documentation by selecting the appropriate tab in the examples.
372
+
373
+
Go to ["Hello React Navigation"](hello-react-navigation.md?config=static) to start writing some code with the static API.
283
374
284
375
### Support a top-level `path` configuration in linking config
285
376
286
-
TODO
377
+
The linking configuration now supports a top-level `path` configuration to define the base path for all the screens in the navigator:
378
+
379
+
```js
380
+
const linking = {
381
+
prefixes: ['https://mysite.com'],
382
+
config: {
383
+
// highlight-next-line
384
+
path:'app',
385
+
screens: {
386
+
Home:'home',
387
+
Details:'details/:id',
388
+
},
389
+
},
390
+
};
391
+
```
392
+
393
+
This can be useful if your app lives under a subpath on the web. For example, if your app lives under `https://mysite.com/app`, you can define the `path` as `app` and the `Details` screen will be accessible at `https://mysite.com/app/details/42`.
394
+
395
+
### Add a `layout` prop for Navigators
396
+
397
+
Navigators now support a `layout`prop. It can be useful for augmenting the navigators with additional UIwith a wrapper. The difference from adding a regular wrapper is that the code in`layout` callback has access to the navigator's state, options etc.:
### Add `layout` and `screenLayout` props for screens
289
415
290
-
TODO
416
+
The `layout` prop makes it easier to provide things such as a global error boundary and suspense fallback for a group of screens without having to manually add HOCs for every screen separately.
291
417
292
-
### Add experimental API for handling deep link after authentication
418
+
It can be used for a single screen with `layout`:
293
419
294
-
TODO
420
+
```jsx
421
+
<Stack.Screen
422
+
name="MyScreen"
423
+
component={MyScreenComponent}
424
+
// highlight-start
425
+
layout={({ children }) => (
426
+
<ErrorBoundary>
427
+
<React.Suspense
428
+
fallback={
429
+
<View style={styles.fallback}>
430
+
<Text style={styles.text}>Loading…</Text>
431
+
</View>
432
+
}
433
+
>
434
+
{children}
435
+
</React.Suspense>
436
+
</ErrorBoundary>
437
+
)}
438
+
// highlight-end
439
+
/>
440
+
```
441
+
442
+
Or with a group or navigator with `screenLayout`:
443
+
444
+
```jsx
445
+
<Stack.Group
446
+
// highlight-start
447
+
screenLayout={({ children }) => (
448
+
<ErrorBoundary>
449
+
<React.Suspense
450
+
fallback={
451
+
<View style={styles.fallback}>
452
+
<Text style={styles.text}>Loading…</Text>
453
+
</View>
454
+
}
455
+
>
456
+
{children}
457
+
</React.Suspense>
458
+
</ErrorBoundary>
459
+
)}
460
+
>
461
+
// highlight-end
462
+
{/* screens */}
463
+
</Stack.Group>
464
+
```
295
465
296
466
### Add a `Button` component to Elements
297
467
298
-
TODO
468
+
The `@react-navigation/elements` package now includes a `Button` component. It has built-in support for navigating to screens, and renders an anchor tag on the Web when used for navigation:
The button follows the [Material Design 3 guidelines](https://m3.material.io/components/buttons/overview).
299
489
300
490
### Add `useAnimatedHeaderHeight` hook to Native Stack Navigator
301
491
302
-
TODO
492
+
The `@react-navigation/native-stack` package now exports a `useAnimatedHeaderHeight` hook. It can be used to animate content based on the header height changes - such as when the large title shrinks to a small title on iOS:
The `@react-navigation/bottom-tabs` package now supports animations. This was one of the most requested features on our Canny board: [TabNavigator Custom Transition](https://react-navigation.canny.io/feature-requests/p/tabnavigator-custom-transition).
507
+
508
+
You can use the `animation` option to customize the animations for the tab transitions:
509
+
510
+
```jsx
511
+
<Tab.Navigator
512
+
screenOptions={{
513
+
// highlight-next-line
514
+
animation:'fade',
515
+
}}
516
+
>
517
+
{/* ... */}
518
+
</Tab.Navigator>
519
+
```
307
520
308
521
### Bottom Tab Navigator can now show tabs on the side
309
522
310
-
TODO
523
+
The `@react-navigation/bottom-tabs` package now supports showing tabs on the side. This will make it easier to build responsive UIs for where you want to show tabs on the bottom on smaller screens and switch to a sidebar on larger screens.
524
+
525
+
You can use the `tabBarPosition` option to customize the position of the tabs:
526
+
527
+
```jsx
528
+
<Tab.Navigator
529
+
screenOptions={{
530
+
// highlight-next-line
531
+
tabBarPosition:'left',
532
+
}}
533
+
>
534
+
{/* ... */}
535
+
</Tab.Navigator>
536
+
```
311
537
312
538
### The drawer implementation is now available in `react-native-drawer-layout` as a standalone package
313
539
314
-
TODO
540
+
The drawer implementation used in `@react-navigation/drawer` is now available as a standalone package called `react-native-drawer-layout`. This makes it easier to use the drawer implementation even if you're not using React Navigation, or if you want to use it without a navigator.
0 commit comments