Skip to content

Commit 897fd59

Browse files
committed
docs: combine navigation guides into one section
1 parent 809c6f8 commit 897fd59

File tree

5 files changed

+118
-73
lines changed

5 files changed

+118
-73
lines changed

docs/docs/guides/08-theming-with-react-navigation.md renamed to docs/docs/guides/bottom-navigation/01-theming.md

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: Theming with React Navigation
2+
title: Theming
33
---
44

55
# Theming with React Navigation
@@ -21,15 +21,12 @@ import {
2121
DefaultTheme as NavigationDefaultTheme,
2222
} from '@react-navigation/native';
2323

24-
import {
25-
MD2LightTheme,
26-
MD2DarkTheme,
27-
} from 'react-native-paper';
24+
import { MD2LightTheme, MD2DarkTheme } from 'react-native-paper';
2825
```
2926

3027
### Material Design 3
3128

32-
From v5, React Native Paper theme colors structure follows the Material Design 3 <i>(known as Material You)</i> colors system, which differs significantly from both the previous Paper's theme and React Navigation theme.
29+
From v5, React Native Paper theme colors structure follows the Material Design 3 <i>(known as Material You)</i> colors system, which differs significantly from both the previous Paper's theme and React Navigation theme.
3330

3431
However, to simplify adapting React Navigation theme colors, to use the ones from React Native Paper, it's worth using a utility called `adaptNavigationTheme` – it accepts navigation-compliant themes in both modes and returns their equivalents adjusted to Material Design 3.
3532

@@ -49,10 +46,7 @@ const { LightTheme, DarkTheme } = adaptNavigationTheme({
4946
Library exports also Material Design 3 themes in both modes:
5047

5148
```js
52-
import {
53-
MD3LightTheme,
54-
MD3DarkTheme,
55-
} from 'react-native-paper';
49+
import { MD3LightTheme, MD3DarkTheme } from 'react-native-paper';
5650
```
5751

5852
## Combining theme objects
@@ -117,8 +111,6 @@ export default function App() {
117111
}
118112
```
119113
120-
121-
122114
Our goal here is to combine those two themes, so that we could control the theme for the entire application from a single place.
123115
124116
To make things easier we can use [deepmerge](https://www.npmjs.com/package/deepmerge) package. We can install it with:
@@ -135,10 +127,7 @@ import {
135127
DarkTheme as NavigationDarkTheme,
136128
DefaultTheme as NavigationDefaultTheme,
137129
} from '@react-navigation/native';
138-
import {
139-
MD2DarkTheme,
140-
MD2LightTheme,
141-
} from 'react-native-paper';
130+
import { MD2DarkTheme, MD2LightTheme } from 'react-native-paper';
142131
import merge from 'deepmerge';
143132

144133
const CombinedDefaultTheme = merge(MD2LightTheme, NavigationDefaultTheme);
@@ -331,19 +320,15 @@ const Header = ({ scene }) => {
331320
}}
332321
>
333322
<Appbar.Content title={scene.route?.name} />
334-
<Switch
335-
color={'red'}
336-
value={isThemeDark}
337-
onValueChange={toggleTheme}
338-
/>
323+
<Switch color={'red'} value={isThemeDark} onValueChange={toggleTheme} />
339324
</Appbar.Header>
340325
);
341326
};
342327
```
343328
344329
And now you can switch between light and dark theme!
345330
346-
![paperGuide1](../../static/screenshots/themingWithReactNavigationDarkLightSwitch.gif)
331+
![paperGuide1](../../../static/screenshots/themingWithReactNavigationDarkLightSwitch.gif)
347332
348333
Thanks to the linking of themes that we did earlier, switching themes can be controlled with only one piece of state.
349334

docs/docs/guides/09-react-navigation.md renamed to docs/docs/guides/bottom-navigation/02-appbar.md

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
---
2-
title: Integrate AppBar with React Navigation
2+
title: AppBar
33
---
44

55
# Integrate AppBar with react-navigation
66

77
## Prerequisites
88

9-
- `react-native-paper`
10-
- `react-navigation`
11-
9+
- `react-native-paper`
10+
- `react-navigation`
11+
1212
We assume that you have already installed the mentioned libraries above, otherwise please check out the guides below.
13-
14-
[React Native Paper - Getting Started](https://callstack.github.io/react-native-paper/docs/guides/getting-started)
15-
16-
[React Navigation - Getting Started](https://reactnavigation.org/docs/getting-started/)
13+
14+
[React Native Paper - Getting Started](https://callstack.github.io/react-native-paper/docs/guides/getting-started)
15+
16+
[React Navigation - Getting Started](https://reactnavigation.org/docs/getting-started/)
1717

1818
## Stack Navigator
1919

@@ -46,7 +46,7 @@ At the moment our navigation stack contains two screens and will render `HomeScr
4646

4747
```js
4848
import React from 'react';
49-
import {View, Text, Button, StyleSheet} from 'react-native';
49+
import { View, Text, Button, StyleSheet } from 'react-native';
5050

5151
function HomeScreen() {
5252
return (
@@ -120,7 +120,8 @@ export default function App() {
120120
initialRouteName="Home"
121121
screenOptions={{
122122
header: (props) => <CustomNavigationBar {...props} />,
123-
}}>
123+
}}
124+
>
124125
<Stack.Screen name="Home" component={HomeScreen} />
125126
<Stack.Screen name="Details" component={DetailsScreen} />
126127
</Stack.Navigator>
@@ -169,7 +170,12 @@ In order to achieve it, we firstly check, if the navigation bar receives a `back
169170
import { Appbar } from 'react-native-paper';
170171
import { getHeaderTitle } from '@react-navigation/elements';
171172

172-
export default function CustomNavigationBar({ navigation, route, options, back }) {
173+
export default function CustomNavigationBar({
174+
navigation,
175+
route,
176+
options,
177+
back,
178+
}) {
173179
const title = getHeaderTitle(options, route.name);
174180

175181
return (
@@ -186,6 +192,7 @@ export default function CustomNavigationBar({ navigation, route, options, back }
186192
### Adding more items to `Appbar`
187193

188194
Another interesting pattern that can be implemented with `react-native-paper` and `react-navigation` is a "menu" button. Thanks to the `Menu` component we can add a nice looking pop-up to our `Appbar`. To implement this feature we need to make a couple of changes in `CustomNavigationBar`:
195+
189196
- Render a `Menu` component
190197
- Pass `Appbar.Action` to the anchor prop
191198
- Add a state to control `Menu` visibility
@@ -204,13 +211,15 @@ import { PaperProvider } from 'react-native-paper';
204211
initialRouteName="Home"
205212
screenOptions={{
206213
header: (props) => <CustomNavigationBar {...props} />,
207-
}}>
214+
}}
215+
>
208216
<Stack.Screen name="Home" component={HomeScreen} />
209217
<Stack.Screen name="Details" component={DetailsScreen} />
210218
</Stack.Navigator>
211219
</NavigationContainer>
212-
</PaperProvider>
220+
</PaperProvider>;
213221
```
222+
214223
:::
215224

216225
We also want the menu to appear only on `HomeScreen`, which means we will render it conditionally based on the `back` prop.
@@ -240,12 +249,8 @@ export default function CustomNavigationBar({
240249
<Menu
241250
visible={visible}
242251
onDismiss={closeMenu}
243-
anchor={
244-
<Appbar.Action
245-
icon="dots-vertical"
246-
onPress={openMenu}
247-
/>
248-
}>
252+
anchor={<Appbar.Action icon="dots-vertical" onPress={openMenu} />}
253+
>
249254
<Menu.Item
250255
onPress={() => {
251256
console.log('Option 1 was pressed');
@@ -276,6 +281,6 @@ Final result:
276281

277282
<img src="/react-native-paper/screenshots/react-navigation-appBar4.gif" width="300" />
278283

279-
That's all we need! We have app bar that contains everything we need to navigate through screens and access an additional menu on the main screen. As you can see, with Material design `Appbar` provided by `react-native-paper` used together with `react-navigation` we can easily create an app that looks and works great.
284+
That's all we need! We have app bar that contains everything we need to navigate through screens and access an additional menu on the main screen. As you can see, with Material design `Appbar` provided by `react-native-paper` used together with `react-navigation` we can easily create an app that looks and works great.
280285

281286
Grab the Expo [snack](https://snack.expo.dev/@react-native-paper/integrate-appbar-with-react-navigation) if you want to check the whole code!
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
---
2+
title: BottomNavigationBar
3+
---
4+
5+
import TabItem from '@theme/TabItem';
6+
import Tabs from '@theme/Tabs';
7+
8+
# Using `BottomNavigation.Bar` with `@react-navigation/bottom-tabs`
9+
10+
`BottomNavigation.Bar` is a Material Design compliant bottom navigation component that can be easily integrated with `@react-navigation/bottom-tabs`. It provides a consistent look and behavior following Material Design guidelines.
11+
12+
:::info
13+
Before getting started, ensure you have installed [`@react-navigation/native` and its dependencies (follow this guide)](https://reactnavigation.org/docs/getting-started), then install [`@react-navigation/bottom-tabs`](https://github.com/react-navigation/react-navigation/tree/main/packages/bottom-tabs):
14+
:::
15+
16+
To implement `BottomNavigation.Bar` as your navigation's `tabBar`, refer to the example below. For a complete implementation, check out the Expo Snack demo provided after the example.
17+
18+
## Example
19+
20+
<Tabs>
21+
<TabItem value="static" label="Static" default>
22+
23+
```js
24+
import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';
25+
import { BottomNavigation } from 'react-native-paper';
26+
27+
const MyTabs = createBottomTabNavigator({
28+
screenOptions: {
29+
animation: 'shift',
30+
},
31+
tabBar: ({ navigation, state, descriptors, insets }) => (
32+
<BottomNavigation.Bar
33+
...
34+
/>
35+
),
36+
screens: {
37+
Home: HomeScreen,
38+
Settings: SettingsScreen,
39+
},
40+
});
41+
```
42+
43+
> 👉 For a complete static example please visit `createBottomTabNavigator` [snack](https://snack.expo.dev/@react-native-paper/static---createbottomtabnavigator-with-bottomnavigationbar).
44+
45+
</TabItem>
46+
<TabItem value="dynamic" label="Dynamic">
47+
48+
```js
49+
import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';
50+
import { BottomNavigation } from 'react-native-paper';
51+
52+
const Tab = createBottomTabNavigator();
53+
54+
function MyTabs() {
55+
return (
56+
<Tab.Navigator
57+
screenOptions={{
58+
animation: 'shift',
59+
}}
60+
tabBar={({ navigation, state, descriptors, insets }) => (
61+
<BottomNavigation.Bar
62+
...
63+
/>
64+
)}
65+
>
66+
<Tab.Screen name="Home" component={HomeScreen} />
67+
<Tab.Screen name="Settings" component={SettingsScreen} />
68+
</Tab.Navigator>
69+
);
70+
}
71+
```
72+
73+
> 👉 For a complete dynamic example please visit `createBottomTabNavigator` [snack](https://snack.expo.dev/@react-native-paper/dynamic---createbottomtabnavigator-with-bottomnavigationbar).
74+
75+
</TabItem>
76+
</Tabs>

docs/docs/guides/09-bottom-navigation.md renamed to docs/docs/guides/bottom-navigation/04-material-bottom-tabs-navigator.md

Lines changed: 6 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,11 @@
11
---
2-
title: Using BottomNavigation with React Navigation
2+
title: Material Bottom Tabs Navigator
33
---
44

55
:::caution
6-
`createMaterialBottomTabNavigator` has been deprecated since `[email protected]`. Please use `@react-navigation/bottom-tabs` version `7.x` or higher and combine it with `BottomNavigation.Bar` for a Material Design look.
7-
8-
```js
9-
import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';
10-
import { BottomNavigation } from 'react-native-paper';
11-
12-
const Tab = createBottomTabNavigator();
13-
14-
function MyTabs() {
15-
return (
16-
<Tab.Navigator
17-
tabBar={({ navigation, state, descriptors, insets }) => (
18-
<BottomNavigation.Bar
19-
...
20-
/>
21-
)}
22-
>
23-
<Tab.Screen name="Home" component={HomeScreen} />
24-
<Tab.Screen name="Profile" component={ProfileScreen} />
25-
</Tab.Navigator>
26-
);
27-
}
28-
```
29-
6+
The `createMaterialBottomTabNavigator` has been deprecated as of `[email protected]`. Instead, use `@react-navigation/bottom-tabs` version `7.x` or later, combined with `BottomNavigation.Bar` to achieve a Material Design look. Refer to the dedicated [guide](./03-bottom-navigation-bar.md) for an example.
307
:::
318

32-
> 👉 For a complete example please visit `createBottomTabNavigator` [snack](https://snack.expo.dev/@react-native-paper/createbottomtabnavigator-with-bottomnavigationbar).
33-
34-
---
35-
36-
_For projects using `react-native-paper` < `5.14.0` and `react-navigation` < `7.x`, proceed as follows:_
37-
389
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.
3910

4011
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.
@@ -273,3 +244,7 @@ function MyTabs() {
273244
);
274245
}
275246
```
247+
248+
```
249+
250+
```
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"label": "Integration with React Navigation",
3+
"position": 9
4+
}

0 commit comments

Comments
 (0)