Skip to content

Commit 3b5d606

Browse files
committed
Document new material themes
1 parent 4312e9d commit 3b5d606

File tree

2 files changed

+57
-33
lines changed

2 files changed

+57
-33
lines changed

versioned_docs/version-8.x/themes.md

Lines changed: 46 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -231,12 +231,12 @@ A theme is a JS object containing a list of colors to use. It contains the follo
231231

232232
- `dark` (`boolean`): Whether this is a dark theme or a light theme
233233
- `colors` (`object`): Various colors used by react navigation components:
234-
- `primary` (`string`): The primary color of the app used to tint various elements. Usually you'll want to use your brand color for this.
235-
- `background` (`string`): The color of various backgrounds, such as the background color for the screens.
236-
- `card` (`string`): The background color of card-like elements, such as headers, tab bars etc.
237-
- `text` (`string`): The text color of various elements.
238-
- `border` (`string`): The color of borders, e.g. header border, tab bar border etc.
239-
- `notification` (`string`): The color of notifications and badge (e.g. badge in bottom tabs).
234+
- `primary` (`ColorValue`): The primary color of the app used to tint various elements. Usually you'll want to use your brand color for this.
235+
- `background` (`ColorValue`): The color of various backgrounds, such as the background color for the screens.
236+
- `card` (`ColorValue`): The background color of card-like elements, such as headers, tab bars etc.
237+
- `text` (`ColorValue`): The text color of various elements.
238+
- `border` (`ColorValue`): The color of borders, e.g. header border, tab bar border etc.
239+
- `notification` (`ColorValue`): The color of notifications and badge (e.g. badge in bottom tabs).
240240
- `fonts` (`object`): Various fonts used by react navigation components:
241241
- `regular` (`object`): Style object for the primary font used in the app.
242242
- `medium` (`object`): Style object for the semi-bold variant of the primary font.
@@ -325,7 +325,32 @@ const MyTheme = {
325325
};
326326
```
327327

328-
Providing a theme will take care of styling of all the official navigators. React Navigation also provides several tools to help you make your customizations of those navigators and the screens within the navigators can use the theme too.
328+
Providing a theme will take care of styling of all the official navigators.
329+
330+
## Built-in themes
331+
332+
React Navigation provides basic light and dark themes:
333+
334+
- `DefaultTheme`
335+
- `DarkTheme`
336+
337+
On Android, it also provides themes based on Material Design:
338+
339+
- `MaterialLightTheme`
340+
- `MaterialDarkTheme`
341+
342+
The Material themes use platform colors to provide dynamic colors that adapt to the user's wallpaper and theme preferences.
343+
344+
You can import the themes from the `@react-navigation/native` package:
345+
346+
```js
347+
import {
348+
DefaultTheme,
349+
DarkTheme,
350+
MaterialLightTheme,
351+
MaterialDarkTheme,
352+
} from '@react-navigation/native';
353+
```
329354

330355
## Using platform colors
331356

@@ -340,47 +365,35 @@ import { DefaultTheme } from '@react-navigation/native';
340365
const MyTheme = {
341366
...DefaultTheme,
342367
colors: Platform.select({
343-
ios: () => ({
368+
ios: {
344369
primary: PlatformColor('systemRed'),
345370
background: PlatformColor('systemGroupedBackground'),
346371
card: PlatformColor('tertiarySystemBackground'),
347372
text: PlatformColor('label'),
348373
border: PlatformColor('separator'),
349374
notification: PlatformColor('systemRed'),
350-
}),
351-
android: () => ({
352-
primary: PlatformColor('@android:color/system_primary_light'),
353-
background: PlatformColor(
354-
'@android:color/system_surface_container_light'
355-
),
356-
card: PlatformColor('@android:color/system_background_light'),
357-
text: PlatformColor('@android:color/system_on_surface_light'),
358-
border: PlatformColor('@android:color/system_outline_variant_light'),
359-
notification: PlatformColor('@android:color/holo_red_light'),
360-
}),
361-
default: () => DefaultTheme.colors,
362-
})(),
375+
},
376+
android: {
377+
primary: PlatformColor('@android:color/system_accent2_600'),
378+
background: PlatformColor('@android:color/system_neutral2_50'),
379+
card: PlatformColor('@android:color/system_neutral2_10'),
380+
text: PlatformColor('@android:color/system_neutral2_900'),
381+
border: PlatformColor('@android:color/system_neutral2_300'),
382+
notification: PlatformColor('@android:color/system_error_600'),
383+
},
384+
default: DefaultTheme.colors,
385+
}),
363386
};
364387
```
365388

366389
This allows your app's navigation UI to automatically adapt to system theme changes and use native colors.
367390

368-
:::note
391+
:::info
369392

370-
When using dynamic colors like `PlatformColor` or `DynamicColorIOS`, React Navigation cannot automatically adjust colors in some scenarios (e.g., adjusting the text color based on background color). In these cases, it will fall back to pre-defined colors according to the theme.
393+
When using dynamic colors like `PlatformColor` or `DynamicColorIOS`, React Navigation cannot automatically adjust colors in some scenarios (e.g., adjusting the text color based on background color). In these cases, it will fall back to pre-defined colors. You may need to pass appropriate colors for such components if needed via options.
371394

372395
:::
373396

374-
## Built-in themes
375-
376-
As operating systems add built-in support for light and dark modes, supporting dark mode is less about keeping hip to trends and more about conforming to the average user expectations for how apps should work. In order to provide support for light and dark mode in a way that is reasonably consistent with the OS defaults, these themes are built in to React Navigation.
377-
378-
You can import the default and dark themes like so:
379-
380-
```js
381-
import { DefaultTheme, DarkTheme } from '@react-navigation/native';
382-
```
383-
384397
## Keeping the native theme in sync
385398

386399
If you're changing the theme in the app, native UI elements such as Alert, ActionSheet etc. won't reflect the new theme. You can do the following to keep the native theme in sync:

versioned_docs/version-8.x/upgrading-from-7.x.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -955,6 +955,17 @@ export default function TabViewExample() {
955955

956956
You can also create your own custom adapter by implementing the required interface. See the [`react-native-tab-view` docs](tab-view.md) for more information.
957957

958+
### New built-in themes base on Material Design are now available
959+
960+
The `@react-navigation/native` package now exports 2 new built-in themes based on Material Design:
961+
962+
- `MaterialLightTheme`
963+
- `MaterialDarkTheme`
964+
965+
These themes use platform colors to provide dynamic colors that adapt to the user's wallpaper and theme preferences.
966+
967+
See [Themes](themes.md#built-in-themes) for more details.
968+
958969
### `useLogger` devtools now shows more information
959970

960971
Previously, the `useLogger` devtools only showed navigation actions. It now shows the following additional information:

0 commit comments

Comments
 (0)