Skip to content

Commit cf203b2

Browse files
committed
feat(v6): remove deprecated public API
- Delete src/deprecated.ts and all MD3*/DefaultTheme/useAppTheme re-exports - Remove createMaterialBottomTabNavigator and entire src/react-navigation/ directory - Remove theme.mode field from Theme type and DarkTheme definition - Remove ThemeBase type - Remove deprecated component props: FAB.small, Button.color, BottomNavigation BaseRoute.color - Remove Card adaptive dark mode logic (tonal surfaces handle dark theme in MD3) - Update example app and docs to use canonical names (Palette, LightTheme, DarkTheme) - Rename internal useAppTheme to _useTheme to avoid confusion with removed public symbol
1 parent d51258f commit cf203b2

49 files changed

Lines changed: 223 additions & 918 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

docs/docs/guides/09-bottom-navigation.md

Lines changed: 73 additions & 210 deletions
Original file line numberDiff line numberDiff line change
@@ -3,246 +3,109 @@ title: Using BottomNavigation with React Navigation
33
---
44

55
:::caution
6-
The `createMaterialBottomTabNavigator` has been deprecated as of `react-native-paper@5.14.0`. Instead, use `@react-navigation/bottom-tabs` version `7.x` or later, combined with `BottomNavigation.Bar` to achieve a Material Design look.
7-
8-
For implementation details, see the [dedicated example](https://callstack.github.io/react-native-paper/docs/components/BottomNavigation/BottomNavigationBar#with-react-navigation).
6+
`createMaterialBottomTabNavigator` was deprecated in `react-native-paper@5.14.0` and removed in `react-native-paper@6.0.0`. Use [`@react-navigation/bottom-tabs`](https://reactnavigation.org/docs/bottom-tab-navigator) (v7+) with [`BottomNavigation.Bar`](https://callstack.github.io/react-native-paper/docs/components/BottomNavigation/BottomNavigationBar) instead.
97
:::
108

11-
A material-design themed tab bar on the bottom of the screen that lets you switch between different routes with animation. Routes are lazily initialized - their screen components are not mounted until they are first focused.
9+
Build a Material Design bottom tab bar by combining two pieces:
1210

13-
This wraps the [`BottomNavigation`](https://callstack.github.io/react-native-paper/docs/components/BottomNavigation/) component from `react-native-paper`, however if you [configure the Babel plugin](https://callstack.github.io/react-native-paper/docs/guides/getting-started/), it won't include the whole library in your bundle.
11+
- `@react-navigation/bottom-tabs` handles routing, state, and screen options.
12+
- `BottomNavigation.Bar` renders the Material 3 tab bar (ripple, badges, shifting/labeled modes).
1413

1514
<img src="/react-native-paper/screenshots/material-bottom-tabs.gif" style={{ width: '420px', maxWidth: '100%', margin: '16px 0' }} />
1615

1716
:::info
18-
To use this navigator, ensure that you have [`@react-navigation/native` and its dependencies (follow this guide)](https://reactnavigation.org/docs/getting-started):
17+
Install [`@react-navigation/native`](https://reactnavigation.org/docs/getting-started) and [`@react-navigation/bottom-tabs@^7`](https://reactnavigation.org/docs/bottom-tab-navigator) first.
1918
:::
2019

21-
> 👉 For a complete example please visit `createMaterialBottomTabNavigator` [snack](https://snack.expo.dev/@react-native-paper/creatematerialbottomtabnavigator)
22-
23-
## API Definition
20+
## Quick example
2421

25-
To use this tab navigator, import it from `react-native-paper/react-navigation`:
22+
Pass a `BottomNavigation.Bar` to the navigator's `tabBar` prop. The bar reads navigation state and dispatches `tabPress` events back:
2623

27-
```js
28-
import { createMaterialBottomTabNavigator } from 'react-native-paper/react-navigation';
24+
```jsx
25+
import { CommonActions } from '@react-navigation/native';
26+
import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';
27+
import { BottomNavigation } from 'react-native-paper';
28+
import MaterialCommunityIcons from '@expo/vector-icons/MaterialCommunityIcons';
2929

30-
const Tab = createMaterialBottomTabNavigator();
31-
32-
function MyTabs() {
33-
return (
34-
<Tab.Navigator>
35-
<Tab.Screen name="Home" component={HomeScreen} />
36-
<Tab.Screen name="Settings" component={SettingsScreen} />
37-
</Tab.Navigator>
38-
);
39-
}
40-
```
41-
42-
> 👉 For a complete usage guide please visit [Tab Navigation](https://reactnavigation.org/docs/tab-based-navigation/)
43-
44-
### Props
45-
46-
The `Tab.Navigator` component accepts following props:
47-
48-
#### `id`
49-
50-
Optional unique ID for the navigator. This can be used with [`navigation.getParent`](https://reactnavigation.org/docs/navigation-prop#getparent) to refer to this navigator in a child navigator.
51-
52-
#### `initialRouteName`
53-
54-
The name of the route to render on first load of the navigator.
55-
56-
#### `screenOptions`
57-
58-
Default options to use for the screens in the navigator.
59-
60-
#### `backBehavior`
61-
62-
This controls what happens when `goBack` is called in the navigator. This includes pressing the device's back button or back gesture on Android.
63-
64-
It supports the following values:
65-
66-
- `firstRoute` - return to the first screen defined in the navigator (default)
67-
- `initialRoute` - return to initial screen passed in `initialRouteName` prop, if not passed, defaults to the first screen
68-
- `order` - return to screen defined before the focused screen
69-
- `history` - return to last visited screen in the navigator; if the same screen is visited multiple times, the older entries are dropped from the history
70-
- `none` - do not handle back button
71-
72-
#### `shifting`
73-
74-
Whether the shifting style is used, the active tab icon shifts up to show the label and the inactive tabs won't have a label.
75-
76-
By default, this is `true` when you have more than 3 tabs. Pass `shifting={false}` to explicitly disable this animation, or `shifting={true}` to always use this animation.
77-
78-
#### `labeled`
79-
80-
Whether to show labels in tabs. When `false`, only icons will be displayed.
81-
82-
#### `activeColor`
83-
84-
Custom color for icon and label in the active tab.
85-
86-
#### `inactiveColor`
87-
88-
Custom color for icon and label in the inactive tab.
89-
90-
#### `barStyle`
91-
92-
Style for the bottom navigation bar. You can pass custom background color here:
93-
94-
```js
95-
<Tab.Navigator
96-
initialRouteName="Home"
97-
activeColor="#f0edf6"
98-
inactiveColor="#3e2465"
99-
barStyle={{ backgroundColor: '#694fad' }}
100-
>
101-
{/* ... */}
102-
</Tab.Navigator>
103-
```
104-
105-
If you have a translucent navigation bar on Android, you can also set a bottom padding here:
106-
107-
```js
108-
<Tab.Navigator
109-
initialRouteName="Home"
110-
activeColor="#f0edf6"
111-
inactiveColor="#3e2465"
112-
barStyle={{ paddingBottom: 48 }}
113-
>
114-
{/* ... */}
115-
</Tab.Navigator>
116-
```
117-
118-
#### `theme`
119-
120-
Enables the customization of default theme attributes (e.g. colors) or facilitates the utilization of a personalized custom theme.
121-
122-
### Options
123-
124-
The following [options](https://reactnavigation.org/docs/screen-options) can be used to configure the screens in the navigator:
125-
126-
#### `title`
127-
128-
Generic title that can be used as a fallback for `headerTitle` and `tabBarLabel`.
129-
130-
#### `tabBarIcon`
131-
132-
Function that given `{ focused: boolean, color: string }` returns a React.Node, to display in the tab bar.
133-
134-
#### `tabBarColor` <div class="badge badge-deprecated">In v5.x works only with theme version 2.</div>
135-
136-
Color for the tab bar when the tab corresponding to the screen is active. Used for the ripple effect. This is only supported when `shifting` is `true`.
137-
138-
#### `tabBarLabel`
139-
140-
Title string of a tab displayed in the tab bar. When undefined, scene `title` is used. To hide, see `labeled` option in the previous section.
141-
142-
#### `tabBarBadge`
143-
144-
Badge to show on the tab icon, can be `true` to show a dot, `string` or `number` to show text.
145-
146-
#### `tabBarAccessibilityLabel`
147-
148-
Accessibility label for the tab button. This is read by the screen reader when the user taps the tab. It's recommended to set this if you don't have a label for the tab.
149-
150-
#### `tabBarTestID`
151-
152-
ID to locate this tab button in tests.
153-
154-
### Events
155-
156-
The navigator can [emit events](https://reactnavigation.org/docs/navigation-events) on certain actions. Supported events are:
157-
158-
#### `tabPress`
159-
160-
This event is fired when the user presses the tab button for the current screen in the tab bar. By default a tab press does several things:
161-
162-
- If the tab is not focused, tab press will focus that tab
163-
- If the tab is already focused:
164-
- If the screen for the tab renders a scroll view, you can use [`useScrollToTop`](https://reactnavigation.org/docs/use-scroll-to-top) to scroll it to top
165-
- If the screen for the tab renders a stack navigator, a `popToTop` action is performed on the stack
166-
167-
To prevent the default behavior, you can call `event.preventDefault`:
168-
169-
```js
170-
React.useEffect(() => {
171-
const unsubscribe = navigation.addListener('tabPress', (e) => {
172-
// Prevent default behavior
173-
174-
e.preventDefault();
175-
// Do something manually
176-
// ...
177-
});
178-
179-
return unsubscribe;
180-
}, [navigation]);
181-
```
182-
183-
### Helpers
184-
185-
The tab navigator adds the following methods to the navigation prop:
186-
187-
#### `jumpTo`
188-
189-
Navigates to an existing screen in the tab navigator. The method accepts following arguments:
190-
191-
- `name` - _string_ - Name of the route to jump to.
192-
- `params` - _object_ - Screen params to pass to the destination route.
193-
194-
<samp id="material-tab-jump-to" />
195-
196-
```js
197-
navigation.jumpTo('Profile', { name: 'Michaś' });
198-
```
199-
200-
## Example
201-
202-
```js
203-
import { createMaterialBottomTabNavigator } from 'react-native-paper/react-navigation';
204-
import MaterialDesignIcons from '@react-native-vector-icons/material-design-icons';
205-
206-
const Tab = createMaterialBottomTabNavigator();
30+
const Tab = createBottomTabNavigator();
20731

20832
function MyTabs() {
20933
return (
21034
<Tab.Navigator
211-
initialRouteName="Feed"
212-
activeColor="#e91e63"
213-
barStyle={{ backgroundColor: 'tomato' }}
35+
screenOptions={{ animation: 'shift' }}
36+
tabBar={({ navigation, state, descriptors, insets }) => (
37+
<BottomNavigation.Bar
38+
navigationState={state}
39+
safeAreaInsets={insets}
40+
onTabPress={({ route, preventDefault }) => {
41+
const event = navigation.emit({
42+
type: 'tabPress',
43+
target: route.key,
44+
canPreventDefault: true,
45+
});
46+
if (event.defaultPrevented) {
47+
preventDefault();
48+
} else {
49+
navigation.dispatch({
50+
...CommonActions.navigate(route.name, route.params),
51+
target: state.key,
52+
});
53+
}
54+
}}
55+
renderIcon={({ route, focused, color }) =>
56+
descriptors[route.key].options.tabBarIcon?.({
57+
focused,
58+
color,
59+
size: 24,
60+
}) ?? null
61+
}
62+
getLabelText={({ route }) => {
63+
const { options } = descriptors[route.key];
64+
return typeof options.tabBarLabel === 'string'
65+
? options.tabBarLabel
66+
: typeof options.title === 'string'
67+
? options.title
68+
: route.name;
69+
}}
70+
/>
71+
)}
21472
>
21573
<Tab.Screen
216-
name="Feed"
217-
component={Feed}
74+
name="Home"
75+
component={HomeScreen}
21876
options={{
219-
tabBarLabel: 'Home',
22077
tabBarIcon: ({ color }) => (
221-
<MaterialDesignIcons name="home" color={color} size={26} />
78+
<MaterialCommunityIcons name="home" color={color} size={26} />
22279
),
22380
}}
22481
/>
22582
<Tab.Screen
226-
name="Notifications"
227-
component={Notifications}
83+
name="Settings"
84+
component={SettingsScreen}
22885
options={{
229-
tabBarLabel: 'Updates',
23086
tabBarIcon: ({ color }) => (
231-
<MaterialDesignIcons name="bell" color={color} size={26} />
232-
),
233-
}}
234-
/>
235-
<Tab.Screen
236-
name="Profile"
237-
component={Profile}
238-
options={{
239-
tabBarLabel: 'Profile',
240-
tabBarIcon: ({ color }) => (
241-
<MaterialDesignIcons name="account" color={color} size={26} />
87+
<MaterialCommunityIcons name="cog" color={color} size={26} />
24288
),
24389
}}
24490
/>
24591
</Tab.Navigator>
24692
);
24793
}
24894
```
95+
96+
## References
97+
98+
- [`BottomNavigation.Bar` props](https://callstack.github.io/react-native-paper/docs/components/BottomNavigation/BottomNavigationBar): `activeColor`, `inactiveColor`, `shifting`, `labeled`, `barStyle`, `theme`, badges.
99+
- [`BottomNavigation.Bar` example](https://callstack.github.io/react-native-paper/docs/components/BottomNavigation/BottomNavigationBar#with-react-navigation): static-config and dynamic-tree variants.
100+
- [React Navigation bottom-tabs](https://reactnavigation.org/docs/bottom-tab-navigator): navigator props, screen options (`tabBarIcon`, `tabBarLabel`, `tabBarBadge`), `tabPress` events, `jumpTo` helper.
101+
102+
## Migration
103+
104+
| Old (removed) | New |
105+
|---|---|
106+
| `createMaterialBottomTabNavigator()` | `createBottomTabNavigator()` from `@react-navigation/bottom-tabs` |
107+
| `<Tab.Navigator activeColor inactiveColor barStyle shifting labeled theme>` | Pass the same props to `<BottomNavigation.Bar>` inside `tabBar` |
108+
| `options.tabBarIcon` / `tabBarLabel` / `tabBarBadge` | Same names; read via `descriptors[route.key].options` in `renderIcon` / `getLabelText` |
109+
| `options.tabBarColor` (theme v2) | Removed. MD3 uses tonal surface colors. |
110+
| `navigation.jumpTo(name, params)` | Same. Provided by `@react-navigation/bottom-tabs`. |
111+
| `tabPress` event | Same. Emitted by `@react-navigation/bottom-tabs`. |

docs/src/components/BannerExample.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import {
99
Avatar,
1010
Button,
1111
FAB,
12-
MD3DarkTheme as DarkTheme,
13-
MD3LightTheme as DefaultTheme,
12+
DarkTheme,
13+
LightTheme,
1414
ProgressBar,
1515
PaperProvider,
1616
RadioButton,
@@ -167,7 +167,7 @@ const Shimmer = () => {
167167
const ThemedBannerExample = () => {
168168
const isDarkTheme = useColorMode().colorMode === 'dark';
169169
return (
170-
<PaperProvider theme={isDarkTheme ? DarkTheme : DefaultTheme}>
170+
<PaperProvider theme={isDarkTheme ? DarkTheme : LightTheme}>
171171
<BannerExample />
172172
</PaperProvider>
173173
);

docs/src/components/GetStartedButtons.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import Link from '@docusaurus/Link';
99
import { useColorMode } from '@docusaurus/theme-common';
1010
import {
1111
Button,
12-
MD3DarkTheme as DarkTheme,
13-
MD3LightTheme as DefaultTheme,
12+
DarkTheme,
13+
LightTheme,
1414
PaperProvider,
1515
} from 'react-native-paper';
1616

@@ -95,7 +95,7 @@ const Shimmer = () => {
9595
const ThemedGetStarted = () => {
9696
const isDarkTheme = useColorMode().colorMode === 'dark';
9797
return (
98-
<PaperProvider theme={isDarkTheme ? DarkTheme : DefaultTheme}>
98+
<PaperProvider theme={isDarkTheme ? DarkTheme : LightTheme}>
9999
<GetStartedButton />
100100
</PaperProvider>
101101
);

example/src/DrawerItems.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
Button,
1010
Dialog,
1111
Drawer,
12-
MD3Colors,
12+
Palette,
1313
Switch,
1414
Text,
1515
TouchableRipple,
@@ -136,8 +136,8 @@ function DrawerItems() {
136136

137137
const coloredLabelTheme = {
138138
colors: {
139-
secondaryContainer: MD3Colors.tertiary80,
140-
onSecondaryContainer: MD3Colors.tertiary20,
139+
secondaryContainer: Palette.tertiary80,
140+
onSecondaryContainer: Palette.tertiary20,
141141
},
142142
};
143143

example/src/Examples/ActivityIndicatorExample.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as React from 'react';
22
import { StyleSheet, View } from 'react-native';
33

4-
import { ActivityIndicator, FAB, List, MD3Colors } from 'react-native-paper';
4+
import { ActivityIndicator, FAB, List, Palette } from 'react-native-paper';
55

66
import ScreenWrapper from '../ScreenWrapper';
77

@@ -41,7 +41,7 @@ const ActivityIndicatorExample = () => {
4141
<List.Section title="Custom color">
4242
<ActivityIndicator
4343
animating={animating}
44-
color={MD3Colors.error20}
44+
color={Palette.error20}
4545
hidesWhenStopped={false}
4646
/>
4747
</List.Section>

0 commit comments

Comments
 (0)