Skip to content

Commit 9406931

Browse files
committed
Add react-native-appearance documentation
1 parent d00398f commit 9406931

File tree

2 files changed

+60
-2
lines changed

2 files changed

+60
-2
lines changed

docs/themes.md

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Providing a light theme and a dark theme is a nice way to let your users adjust
88

99
# Built-in themes
1010

11-
> Note: support for built-in themes requires react-navigation@>=3.12.0-alpha! There is not a stable release with support for this yet. Skip ahead to "Custom themes using React context" if you'd like to learn more about how you can use themes today on a stable release.
11+
> Note: support for built-in themes requires react-navigation@>=3.12.0!
1212
1313
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. You can pass in a `theme` prop to your app container component in order to switch between light and dark mode, and the value of that `theme` prop can come from whichever API you use to detect user preferences for dark mode, or in the case of older operating system versions, from a custom configuration within your app UI.
1414

@@ -21,6 +21,35 @@ export default () => <Navigation theme="light">;
2121

2222
This will take care of styling the stack navigator, bottom tab navigator, and drawer navigator for you. React Navigation also provides several tools to help you make your customizations of those navigators and the screens within the navigators support both themes too.
2323

24+
## Using the operating system preferences
25+
26+
At the time of writing, `react-native` does not currently support detecting the operating system color scheme preferences in the core ([you can follow this pull request](https://github.com/facebook/react-native/pull/26172)). Until it is part of core and you have updated to the version that includes it, you can use `react-native-appearance`.
27+
28+
> Note: if you use the Expo managed workflow, this requires SDK 35+
29+
30+
First, you need to install `react-native-appearance`. [Follow the instructions in the README](https://github.com/expo/react-native-appearance).
31+
32+
Once you've installed it, set your root component up as follows:
33+
34+
```js
35+
import { AppearanceProvider, useColorScheme } from 'react-native-appearance';
36+
37+
// Other navigation code goes here...
38+
let Navigation = createAppContainer(RootStack);
39+
40+
export default () => {
41+
let theme = useColorScheme();
42+
43+
return (
44+
<AppearanceProvider>
45+
<Navigation theme={theme}>
46+
</AppearanceProvider>
47+
)
48+
}
49+
```
50+
51+
If the version of React Native you are using doesn't support hooks yet, you can use the `Appearance.addChangeListener(cb)` and `Appearance.getColorScheme()` functions as described in the [usage section of the README](https://github.com/expo/react-native-appearance#usage).
52+
2453
## Using the currently selected theme
2554

2655
Two tools are available to gain access to the theme in any component that descends from the app navigation container: `useTheme` and `ThemeConext`.

website/versioned_docs/version-3.x/themes.md

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Providing a light theme and a dark theme is a nice way to let your users adjust
99

1010
# Built-in themes
1111

12-
> Note: support for built-in themes requires react-navigation@>=3.12.0-alpha! There is not a stable release with support for this yet. Skip ahead to "Custom themes using React context" if you'd like to learn more about how you can use themes today on a stable release.
12+
> Note: support for built-in themes requires react-navigation@>=3.12.0!
1313
1414
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. You can pass in a `theme` prop to your app container component in order to switch between light and dark mode, and the value of that `theme` prop can come from whichever API you use to detect user preferences for dark mode, or in the case of older operating system versions, from a custom configuration within your app UI.
1515

@@ -22,6 +22,35 @@ export default () => <Navigation theme="light">;
2222

2323
This will take care of styling the stack navigator, bottom tab navigator, and drawer navigator for you. React Navigation also provides several tools to help you make your customizations of those navigators and the screens within the navigators support both themes too.
2424

25+
## Using the operating system preferences
26+
27+
At the time of writing, `react-native` does not currently support detecting the operating system color scheme preferences in the core ([you can follow this pull request](https://github.com/facebook/react-native/pull/26172)). Until it is part of core and you have updated to the version that includes it, you can use `react-native-appearance`.
28+
29+
> Note: if you use the Expo managed workflow, this requires SDK 35+
30+
31+
First, you need to install `react-native-appearance`. [Follow the instructions in the README](https://github.com/expo/react-native-appearance).
32+
33+
Once you've installed it, set your root component up as follows:
34+
35+
```js
36+
import { AppearanceProvider, useColorScheme } from 'react-native-appearance';
37+
38+
// Other navigation code goes here...
39+
let Navigation = createAppContainer(RootStack);
40+
41+
export default () => {
42+
let theme = useColorScheme();
43+
44+
return (
45+
<AppearanceProvider>
46+
<Navigation theme={theme}>
47+
</AppearanceProvider>
48+
)
49+
}
50+
```
51+
52+
If the version of React Native you are using doesn't support hooks yet, you can use the `Appearance.addChangeListener(cb)` and `Appearance.getColorScheme()` functions as described in the [usage section of the README](https://github.com/expo/react-native-appearance#usage).
53+
2554
## Using the currently selected theme
2655

2756
Two tools are available to gain access to the theme in any component that descends from the app navigation container: `useTheme` and `ThemeConext`.

0 commit comments

Comments
 (0)