Skip to content

Commit 992cbf3

Browse files
committed
Add a note about keeping native theme in sync
1 parent 23f6b68 commit 992cbf3

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

versioned_docs/version-6.x/themes.md

+18
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,24 @@ You can import the default and dark themes like so:
7777
import { DefaultTheme, DarkTheme } from '@react-navigation/native';
7878
```
7979

80+
## Keeping the native theme in sync
81+
82+
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:
83+
84+
```js
85+
React.useEffect(() => {
86+
const colorScheme = theme.dark ? 'dark' : 'light';
87+
88+
if (Platform.OS === 'web') {
89+
document.documentElement.style.colorScheme = colorScheme;
90+
} else {
91+
Appearance.setColorScheme(colorScheme);
92+
}
93+
}, [theme.dark]);
94+
```
95+
96+
Alternatively, you can use the [`useColorScheme`](#using-the-operating-system-preferences) hook to get the current native color scheme and update the theme accordingly.
97+
8098
## Using the operating system preferences
8199

82100
On iOS 13+ and Android 10+, you can get user's preferred color scheme (`'dark'` or `'light'`) with the ([`useColorScheme` hook](https://reactnative.dev/docs/usecolorscheme)).

versioned_docs/version-7.x/themes.md

+18
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,24 @@ You can import the default and dark themes like so:
336336
import { DefaultTheme, DarkTheme } from '@react-navigation/native';
337337
```
338338

339+
## Keeping the native theme in sync
340+
341+
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:
342+
343+
```js
344+
React.useEffect(() => {
345+
const colorScheme = theme.dark ? 'dark' : 'light';
346+
347+
if (Platform.OS === 'web') {
348+
document.documentElement.style.colorScheme = colorScheme;
349+
} else {
350+
Appearance.setColorScheme(colorScheme);
351+
}
352+
}, [theme.dark]);
353+
```
354+
355+
Alternatively, you can use the [`useColorScheme`](#using-the-operating-system-preferences) hook to get the current native color scheme and update the theme accordingly.
356+
339357
## Using the operating system preferences
340358

341359
On iOS 13+ and Android 10+, you can get user's preferred color scheme (`'dark'` or `'light'`) with the ([`useColorScheme` hook](https://reactnative.dev/docs/usecolorscheme)).

0 commit comments

Comments
 (0)