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: docs/docs/guides/08-theming-with-react-navigation.md
+13-13Lines changed: 13 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,9 +4,9 @@ title: Theming with React Navigation
4
4
5
5
# Theming with React Navigation
6
6
7
-
In this guide we will look into how to apply theming for an application using React Native Paper and React Navigation at the same time.
7
+
In this guide, we will look into how to apply theming for an application using React Native Paper and React Navigation at the same time.
8
8
9
-
Offering different theme options, especially dark/light ones, becomes increasingly a standard requirement of the modern mobile application. Fortunately, both React Navigation and React Native Paper support configurable theming out-of-the-box.
9
+
Offering different theme options, especially dark/light ones, has become increasingly a standard requirement of the modern mobile application. Fortunately, both React Navigation and React Native Paper support configurable theming out-of-the-box.
10
10
But how to make them work together?
11
11
12
12
## Themes adaptation
@@ -29,9 +29,9 @@ import {
29
29
30
30
### Material Design 3
31
31
32
-
From v5, React Native Paper theme colors structure is following the Material Design 3 <i>(known as Material You)</i> colors system, which differs significantly from both previous Paper's theme and React Navigation theme.
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.
33
33
34
-
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 navigationcompliant themes in both modes and returns their equivalents adjusted to Material Design 3.
34
+
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.
35
35
36
36
```ts
37
37
import {
@@ -58,8 +58,8 @@ import {
58
58
## Combining theme objects
59
59
60
60
Both libraries require a wrapper to be used at the entry point of the application.
61
-
React Navigation exposes `NavigationContainer` which ensures that navigation works correctly, but also accepts `theme` as an optional property. Read more about setting up navigation [here](https://reactnavigation.org/docs/getting-started/).
62
-
For React Native Paper theme to work, we need to use `PaperProvider` also at application's entry point.
61
+
React Navigation exposes `NavigationContainer`, which ensures that navigation works correctly and accepts `theme` as an optional property. Read more about setting up navigation [here](https://reactnavigation.org/docs/getting-started/).
62
+
For React Native Paper theme to work, we need to use `PaperProvider` also at the application's entry point.
@@ -121,7 +121,7 @@ export default function App() {
121
121
122
122
Our goal here is to combine those two themes, so that we could control the theme for the entire application from a single place.
123
123
124
-
To make things easier we can use [deepmerge](https://www.npmjs.com/package/deepmerge) package. With `yarn` we can install it like this
124
+
To make things easier we can use [deepmerge](https://www.npmjs.com/package/deepmerge) package. We can install it with:
125
125
126
126
```bash npm2yarn
127
127
npm install deepmerge
@@ -243,15 +243,15 @@ export default function App() {
243
243
244
244
## Customizing theme
245
245
246
-
We don't need to limit ourselves to the themes offered by the libraries in default. Both packages allow for custom themes to be applied.
247
-
You can learn all about it their documentations:
246
+
We don't need to limit ourselves to the themes offered by the libraries' default. Both packages allow for custom themes to be applied.
247
+
You can learn all about it in their documentation:
248
248
249
249
- [Theming in React Navigation](https://reactnavigation.org/docs/themes/)
250
250
- [Theming in React Native Paper](https://callstack.github.io/react-native-paper/docs/guides/theming)
251
251
252
252
## React Context for theme customization
253
253
254
-
Now, we wouldn't want to stay forever with dark theme being on, which is why we need to gain the ability to control theme dynamically. A bit of state management is needed for this purpose.
254
+
Now, we wouldn't want to stay on dark theme forever, which is why we need to gain the ability to control theme dynamically. A bit of state management is needed for this purpose.
255
255
256
256
React Context proves itself very useful in handling cross-cutting concerns like global theme handling, so we will use just that.
257
257
@@ -311,7 +311,7 @@ export default function App() {
311
311
}
312
312
```
313
313
314
-
Now that the Context is available at every component, all we need to do is import it. Next thing is to provide the user with some UI element to control changing the theme. We will use `Paper`'s [Switch](https://callstack.github.io/react-native-paper/docs/components/Switch) for this purpose.
314
+
Now that the Context is available at every component, all we need to do is import it. Next, provide the user with some UI element to control changing the theme. We will use `Paper`'s [Switch](https://callstack.github.io/react-native-paper/docs/components/Switch) for this purpose.
315
315
316
316
```js
317
317
importReactfrom'react';
@@ -347,10 +347,10 @@ And now you can switch between light and dark theme!
347
347
348
348
Thanks to the linking of themes that we did earlier, switching themes can be controlled with only one piece of state.
349
349
350
-
React Native Paper components will automatically use provided theme thanks to the `PaperProvider` that is wrapped around the entry point of our application, but we can also access theme values manually with `useTheme` hook,
350
+
React Native Paper components will automatically use the provided theme thanks to the `PaperProvider` that is wrapped around the entry point of our application, but we can also access theme values manually with `useTheme` hook,
351
351
exposed by the library. You can see how it's done in the `Header` component code above.
352
352
353
353
If light/dark themes are not enough for your use case, you can learn more about creating Material Design themes [here](https://material.io/design/material-theming/implementing-your-theme.html#color).
354
-
On `main` branch of the example app, you will find implemented [Menu](https://callstack.github.io/react-native-paper/docs/components/Menu) component, which allows to choose a few custom themes. Inspecting code in `utils` and `Header` may give you some idea how to use your own themes with `Paper`, in addition to dedicated [docs](https://callstack.github.io/react-native-paper/docs/components/Menu).
354
+
On `main` branch of the example app, you will find implemented [Menu](https://callstack.github.io/react-native-paper/docs/components/Menu) component, which allows you to choose a few custom themes. Inspecting code in `utils` and `Header` may give you some idea of how to use your own themes with `Paper`, in addition to dedicated [docs](https://callstack.github.io/react-native-paper/docs/components/Menu).
355
355
356
356
Read more about integrating `Paper` with `React Navigation` in a brilliant [article](https://reactnavigation.org/blog/2020/01/29/using-react-navigation-5-with-react-native-paper/) by [@trensik](https://twitter.com/trensik)
0 commit comments