Repository navigation
feat(navigation-bar)!: modernize to Material Design 3 #5006
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
c3aef33
e0da53e
b384ecb
33bdcb9
f16775a
c56ceff
39b2f82
98346d3
4076ce8
57d7506
6937a17
b19e402
83b1a8b
2057612
8fe9cf7
4e9a651
fb3c953
c1bf911
0d49772
c9fc66a
e6bd72c
a01e439
4c0b60a
07be96e
3281245
b47d0d8
55913bc
a92737a
89298cf
1a5bf26
995cecd
2227ffc
e37fcfb
6695dd4
2142b24
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -161,8 +161,7 @@ Hardcoded default test IDs have been removed for the components listed below: | |
| - `AnimatedFAB`: `animated-fab` | ||
| - `Appbar.Content`: `appbar-content` | ||
| - `Appbar.Header`: `appbar-header` | ||
| - `BottomNavigation`: `bottom-navigation` | ||
| - `BottomNavigation.Bar`: `bottom-navigation-bar` | ||
| - `BottomNavigation` and `BottomNavigation.Bar`: `bottom-navigation` and `bottom-navigation-bar`. Both components are removed, see [BottomNavigation](#bottomnavigation). | ||
| - `Button`: `button` | ||
| - `Card`: `card` | ||
| - `Chip`: `chip` | ||
|
|
@@ -185,7 +184,6 @@ If you were relying on internal test IDs, update your tests not to rely on inter | |
|
|
||
| Some components now accept explicit `testID` props for their interactable elements: | ||
|
|
||
| - `BottomNavigation`: `barTestID` for the internal `BottomNavigation.Bar`, replacing the previous `${testID}-bar` derivation. | ||
| - `Chip`: `closeIconTestID` for the close icon button. | ||
| - `Dialog` and `Modal`: `overlayTestID` for the overlay displayed behind the content. | ||
| - `Menu`: `overlayTestID` for the overlay displayed behind the menu. | ||
|
|
@@ -412,7 +410,7 @@ Components now use React Native's `aria-*` props and `role` instead of the `acce | |
|
|
||
| Props that label a part of a component keep their names, e.g. `closeIconAccessibilityLabel` on `Chip` and `dismissAccessibilityLabel` on `Modal`. | ||
|
|
||
| Keys inside data objects changed the same way: the `routes` of `BottomNavigation` and the `buttons` of `SegmentedButtons` now take `'aria-label'`. The old `accessibilityLabel` key is ignored, and TypeScript doesn't report it in `routes`. | ||
| Keys inside data objects changed the same way: the `routes` of `NavigationBar` (`BottomNavigation` in 5.x) and the `buttons` of `SegmentedButtons` now take `'aria-label'`. The old `accessibilityLabel` key is ignored, and TypeScript doesn't report it in `routes`. | ||
|
|
||
| ```diff | ||
| <Checkbox.Item | ||
|
|
@@ -465,7 +463,7 @@ Interactive components now draw the Material Design 3 keyboard focus indicator: | |
|
|
||
| `Snackbar` rings its action and close button in `theme.colors.inversePrimary`, the color of its action label, because `secondary` barely shows on its `inverseSurface` background. If a component's background is the ring color, such as an `Appbar` with a `secondary` background, the rings of the controls on it don't show: give those controls a `theme` with a contrasting `secondary`. `Appbar.Action`, `Appbar.BackAction` and `Appbar.Content` read the `theme` of the `Appbar` they are rendered in from context, and the actions get it inside a `Tooltip` or a `View` too, so you can give that `theme` to the `Appbar` instead of to each control. See [Parts read from the `Appbar`](#parts-read-from-the-appbar). | ||
|
|
||
| Components that fill a clipping container or touch their neighbours draw the ring 3dp inside their edge instead: `List.Item`, `List.Accordion`, `Checkbox.Item`, `RadioButton.Item`, `Menu.Item`, the `FAB.Menu` items, `Drawer.Item`, the `BottomNavigation` tabs, `DataTable.Row`, `DataTable.Cell`, `DataTable.Title` and `SegmentedButtons`. `Drawer.CollapsedItem` draws it around its icon and label, 2dp clear of the active indicator. `FAB` and `Switch` draw this ring instead of their own, and `Checkbox` keeps its circular ring around the state layer. | ||
| Components that fill a clipping container or touch their neighbours draw the ring 3dp inside their edge instead: `List.Item`, `List.Accordion`, `Checkbox.Item`, `RadioButton.Item`, `Menu.Item`, the `FAB.Menu` items, `Drawer.Item`, the `NavigationBar` tabs, `DataTable.Row`, `DataTable.Cell`, `DataTable.Title` and `SegmentedButtons`. `Drawer.CollapsedItem` draws it around its icon and label, 2dp clear of the active indicator. `FAB` and `Switch` draw this ring instead of their own, and `Checkbox` keeps its circular ring around the state layer. | ||
|
|
||
| A `TouchableRipple`, and every component built on it, rings only while it can be pressed. A disabled one shows no ring. One with no touch handler and no `disabled` is the plain view described in [TouchableRipple without a press handler](#touchableripple-without-a-press-handler): it isn't a keyboard stop, so it never rings. This applies to `TouchableRipple` only: a `Drawer.CollapsedItem` without `onPress` is still a keyboard stop and rings. A `Switch` without `onValueChange` is read-only, so it isn't a keyboard stop and never rings, as [Switches without `onValueChange`](#switches-without-onvaluechange) explains. | ||
|
|
||
|
|
@@ -637,6 +635,82 @@ e.g.: | |
| + </View> | ||
| ``` | ||
|
|
||
| ### BottomNavigation | ||
|
|
||
| `BottomNavigation` has been removed. Paper no longer ships a component that owns your tab scenes; the Material 3 navigation bar is now `NavigationBar`, a standalone bar you render next to your own navigator (React Navigation, or your own state). | ||
|
|
||
| | v5 | v6 | | ||
| | --------------------------------------------------------------------- | ------------------------------------------------------------------------ | | ||
| | `BottomNavigation`, `BottomNavigation.Bar` | `NavigationBar` | | ||
| | `BottomNavigationProps`, `BottomNavigationRoute` | `NavigationBarProps`, `NavigationBarRoute` | | ||
| | `BottomNavigation.SceneMap`, `renderScene`, `onIndexChange` | render the active scene yourself, alongside the bar | | ||
| | `getLazy`, `route.lazy` | removed (the bar no longer owns the scenes) | | ||
| | `sceneAnimationEnabled`, `sceneAnimationType`, `sceneAnimationEasing` | removed with the scene container | | ||
| | `shifting` | removed (including the active-icon shift and inactive-label transitions) | | ||
| | `barStyle` | `style` | | ||
| | `style` (the whole `BottomNavigation`, scenes and bar) | wrap your scenes and the bar in your own `View` (`style` styles the bar) | | ||
| | `animationEasing` | removed (the indicator uses M3 motion from the theme) | | ||
| | `barStyle` with `Animated.Value` | `style` with static styles only | | ||
| | `barTestID`, `${testID}-bar` | `testID` on `NavigationBar` | | ||
| | n/a | new `variant` (`'stacked' \| 'horizontal'`) for the item layout | | ||
|
|
||
| The bar is 64dp tall instead of 80dp, which is the height of the M3 flexible navigation bar. If your app moves a `FAB` or a `Snackbar` up by the height of the bar, change that offset. The label of the active tab uses `secondary` instead of `onSurface`. | ||
|
|
||
| ```diff | ||
| + const scenes = { home: HomeScreen, settings: SettingsScreen }; | ||
| + const ActiveScene = scenes[routes[index].key]; | ||
| + | ||
| - <BottomNavigation | ||
| - navigationState={{ index, routes }} | ||
| - onIndexChange={setIndex} | ||
| - renderScene={BottomNavigation.SceneMap(scenes)} | ||
| - /> | ||
| + <> | ||
| + <ActiveScene /> | ||
| + <NavigationBar | ||
| + navigationState={{ index, routes }} | ||
| + onTabPress={({ route }) => setIndex(routes.findIndex((r) => r.key === route.key))} | ||
| + /> | ||
| + </> | ||
| ``` | ||
|
|
||
| This renders only the active route, so a screen unmounts when you leave its tab, unlike v5 which kept the visited screens mounted. If your app depends on that state, render `NavigationBar` as the [`tabBar` of React Navigation's bottom tabs](./navigation-bar#quick-example), which keeps screens mounted. | ||
|
|
||
| `onTabPress` & `onTabLongPress` callbacks receive only pressed `route`. The v5 event object also carried `preventDefault()` & `defaultPrevented`, so code that reads them now throws `preventDefault is not a function`. The bar never navigates on its own, so navigator's own `tabPress` event decides whether press is handled: | ||
|
|
||
| ```diff | ||
| tabBar={({ navigation, state, descriptors, insets }) => ( | ||
| <NavigationBar | ||
| navigationState={state} | ||
| safeAreaInsets={insets} | ||
| - onTabPress={({ route, preventDefault }) => { | ||
| + onTabPress={({ route }) => { | ||
| const event = navigation.emit({ | ||
| type: 'tabPress', | ||
| target: route.key, | ||
| canPreventDefault: true, | ||
| }); | ||
|
|
||
| - if (event.defaultPrevented) { | ||
| - preventDefault(); | ||
| - } else { | ||
| + if (!event.defaultPrevented) { | ||
| navigation.dispatch({ | ||
| ...CommonActions.navigate(route.name, route.params), | ||
| target: state.key, | ||
| }); | ||
| } | ||
| }} | ||
| /> | ||
| )} | ||
| ``` | ||
|
|
||
| The `animationEasing` prop is gone along with animation it configured. Active indicator now follows the motion from theme (`theme.motion`) and honors reduce motion preference. | ||
|
|
||
| Unlike v5 `barStyle`, the `style` prop no longer accepts `Animated.Value` or `Animated.AnimatedInterpolation`. Pass static styles. | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that mentioning v5 and its behavior is completely redundant except direct comparison before vs after. Imo migration should only describe the current behavior and implementation so we could drop these mentions. What do you think?
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. agreed for this line. I'd keep the table and the snippets though - people... or agents 😄 read this guide when they move from v5 so they need to see what to change. wdyt?
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, the table should definitely stay like before vs after snippets! |
||
|
|
||
| `NavigationBar` also does not set a default `testID`. If your tests looked up `bottom-navigation-bar` (or its `-container` / `-content` / `-content-wrapper` children), pass a `testID` explicitly. | ||
|
jacekAtCK marked this conversation as resolved.
Resolved
|
||
|
|
||
| ### Surface | ||
|
|
||
| - The `elevation` prop no longer accepts a React Native `Animated.Value`. Any `elevation` changes are animated automatically. | ||
|
|
@@ -2124,7 +2198,7 @@ const TertiarySwitch = ({ | |
|
|
||
| `Icon`'s `source` prop is typed as `IconSource` instead of `any`, so a value that isn't an icon name, an image source or a render function, such as a boolean or `undefined`, is now a type error. `Icon` still renders nothing for those values. | ||
|
|
||
| If you pass a field that can be `undefined`, such as an optional `focusedIcon` on a route in `BottomNavigation`'s `renderIcon`, check it first: | ||
| If you pass a field that can be `undefined`, such as an optional `focusedIcon` on a route in `NavigationBar`'s `renderIcon`, check it first: | ||
|
|
||
| ```diff | ||
| -renderIcon={({ route, color }) => ( | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In v5
stylestyled the wholeBottomNavigationcontainer and now it styles the bar, which should be in the table. A line about the height change from 80 to 64dp would also help apps that offset a FAB or Snackbar by it.