Skip to content

Commit cd8b326

Browse files
committed
[docs] Update Appearance API docs, add Mermaid diagram support
Update the `Appearance` and `useColorScheme` API reference pages with clearer descriptions, consistent terminology ("color scheme" over "user interface style"), and aligned return value docs between the two pages. Adds `@docusaurus/theme-mermaid`, and includes a Mermaid flowchart on the Appearance page illustrating the `setColorScheme` override behaviour.
1 parent fcb433e commit cd8b326

8 files changed

Lines changed: 1810 additions & 825 deletions

File tree

docs/appearance.md

Lines changed: 37 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; import con
99
import {Appearance} from 'react-native';
1010
```
1111

12-
The `Appearance` module exposes information about the user's appearance preferences, such as their preferred color scheme (light or dark).
12+
The `Appearance` module exposes information about the user's appearance preferences, such as their preferred system color scheme (light or dark).
1313

1414
#### Developer notes
1515

@@ -53,7 +53,26 @@ if (colorScheme === 'dark') {
5353
}
5454
```
5555

56-
Although the color scheme is available immediately, this may change (e.g. scheduled color scheme change at sunrise or sunset). Any rendering logic or styles that depend on the user preferred color scheme should try to call this function on every render, rather than caching the value. For example, you may use the [`useColorScheme`](usecolorscheme) React hook as it provides and subscribes to color scheme updates, or you may use inline styles rather than setting a value in a `StyleSheet`.
56+
Although the color scheme is available immediately, this may change when not overridden via `setColorScheme()` (e.g. scheduled color scheme change at sunrise or sunset). Any rendering logic or styles that depend on the user preferred color scheme should try to call this function on every render, rather than caching the value.
57+
58+
**Recommended:** Use the [`useColorScheme`](usecolorscheme) hook.
59+
60+
### App-level overriding
61+
62+
`setColorScheme()` overrides the color scheme at the application level — it does not affect the system setting or other applications. Passing `'unspecified'` removes any override, restoring the system preference.
63+
64+
```mermaid
65+
flowchart TD
66+
USC["useColorScheme()"] --> GCS["getColorScheme()"]
67+
GCS --> DEC{App override?}
68+
DEC -- "NO / reset via setColorScheme('unspecified')" --> SYS["System preference\n'light' or 'dark'"]
69+
DEC -- "YES — setColorScheme('light' | 'dark')" --> OVR["'light' or 'dark' (static)"]
70+
71+
classDef fn fill:#dce8f8,stroke:#4a90d9,color:#1a1a1a
72+
classDef out fill:#f0f4f8,stroke:#8faabb,color:#1a1a1a
73+
class USC,GCS fn
74+
class OVR,SYS out
75+
```
5776

5877
---
5978

@@ -64,42 +83,37 @@ Although the color scheme is available immediately, this may change (e.g. schedu
6483
### `getColorScheme()`
6584

6685
```tsx
67-
static getColorScheme(): 'light' | 'dark' | null;
86+
static getColorScheme(): 'light' | 'dark' | 'unspecified' | null;
6887
```
6988

70-
Indicates the current user preferred color scheme. The value may be updated later, either through direct user action (e.g. theme selection in device settings or application-level selected user interface style via `setColorScheme`) or on a schedule (e.g. light and dark themes that follow the day/night cycle).
89+
Returns the active color scheme. The value may be updated later, either through direct user action (e.g. theme selection in device settings or application-level selected user interface style via `setColorScheme`) or on a schedule (e.g. light and dark themes that follow the day/night cycle).
7190

72-
Supported color schemes:
91+
Return values:
7392

74-
- `'light'`: The user prefers a light color theme.
75-
- `'dark'`: The user prefers a dark color theme.
76-
- `null`: The user has not indicated a preferred color theme.
93+
- `'light'`: The light color scheme is applied.
94+
- `'dark'`: The dark color scheme is applied.
95+
- `'unspecified'`: **_Never returned_** (incorrectly typed).
96+
- `null`: May be returned if the native Appearance module is not available.
7797

78-
See also: `useColorScheme` hook.
79-
80-
:::note
81-
`getColorScheme()` will always return `light` when debugging with Chrome.
82-
:::
98+
See also: [`useColorScheme`](usecolorscheme) (hook).
8399

84100
---
85101

86102
### `setColorScheme()`
87103

88104
```tsx
89-
static setColorScheme('light' | 'dark' | null): void;
105+
static setColorScheme('light' | 'dark' | 'unspecified'): void;
90106
```
91107

92-
Force the application to always adopt a light or dark interface style. The default value is `null` which causes the application to inherit the system's interface style. If you assign a different value, the new style applies to the application and all native elements within the application (Alerts, Pickers etc).
108+
Forces the application to always adopt a light or dark interface style. The change applies to the application and all native elements within it (Alerts, Pickers, etc.).
93109

94-
Supported color schemes:
110+
This is an app-level override — it does not affect the system's selected interface style or any style set in other applications.
95111

96-
- `light`: Apply light user interface style.
97-
- `dark`: Apply dark user interface style.
98-
- null: Follow the system's interface style.
112+
Supported values:
99113

100-
:::note
101-
The change will not affect the system's selected interface style or any style set in other applications.
102-
:::
114+
- `'light'`: Apply light color scheme.
115+
- `'dark'`: Apply dark color scheme.
116+
- `'unspecified'`: Follow the system color scheme (removes any override).
103117

104118
---
105119

@@ -111,4 +125,4 @@ static addChangeListener(
111125
): NativeEventSubscription;
112126
```
113127

114-
Add an event handler that is fired when appearance preferences change.
128+
Add an event handler that is fired when appearance preferences change. On iOS and Android, the `colorScheme` value in the callback is always `'light'` or `'dark'`.

docs/usecolorscheme.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@ title: useColorScheme
77
import {useColorScheme} from 'react-native';
88
```
99

10-
The `useColorScheme` React hook provides and subscribes to color scheme updates from the [`Appearance`](appearance) module. The return value indicates the current user preferred color scheme. The value may be updated later, either through direct user action (e.g. theme selection in device settings) or on a schedule (e.g. light and dark themes that follow the day/night cycle).
10+
The `useColorScheme` React hook provides and subscribes to color scheme updates from the [`Appearance`](appearance) module. The return value indicates the active color scheme. The value may be updated later, either through direct user action (e.g. theme selection in device settings or application-level selected user interface style via [`setColorScheme`](appearance#setcolorscheme)) or on a schedule (e.g. light and dark themes that follow the day/night cycle).
1111

12-
### Supported color schemes
12+
### Return values
1313

14-
- `"light"`: The user prefers a light color theme.
15-
- `"dark"`: The user prefers a dark color theme.
16-
- `null`: The user has not indicated a preferred color theme.
14+
- `'light'`: The light color scheme is applied.
15+
- `'dark'`: The dark color scheme is applied.
16+
- `'unspecified'`: **_Never returned_** (incorrectly typed).
17+
- `null`: May be returned if the native Appearance module is not available.
1718

1819
---
1920

website/docusaurus.config.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ const isDeployPreview =
7070
(!!process.env.VERCEL && process.env.VERCEL_ENV === 'preview');
7171

7272
const config: Config = {
73+
markdown: {
74+
mermaid: true,
75+
},
76+
themes: ['@docusaurus/theme-mermaid'],
7377
future: {
7478
// Turns Docusaurus v4 future flags on to make it easier to upgrade later
7579
v4: true,
@@ -613,6 +617,16 @@ const config: Config = {
613617
{name: 'twitter:site', content: '@reactnative'},
614618
{name: 'mobile-web-app-capable', content: 'yes'},
615619
],
620+
mermaid: {
621+
theme: {
622+
light: 'neutral',
623+
dark: 'dark',
624+
},
625+
options: {
626+
fontFamily:
627+
'"Optimistic Display", system-ui, -apple-system, sans-serif',
628+
},
629+
},
616630
} satisfies Preset.ThemeConfig,
617631
};
618632

website/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
"@docusaurus/plugin-google-gtag": "3.10.0",
5656
"@docusaurus/plugin-pwa": "3.10.0",
5757
"@docusaurus/preset-classic": "3.10.0",
58+
"@docusaurus/theme-mermaid": "3.10.0",
5859
"docusaurus-plugin-sass": "^0.2.6",
5960
"react": "^19.2.4",
6061
"react-dom": "^19.2.4",

website/src/css/customTheme.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,10 @@ hr {
511511
}
512512
}
513513

514+
.docusaurus-mermaid-container {
515+
text-align: center;
516+
}
517+
514518
.docusaurus-highlight-code-line {
515519
background-color: var(--light);
516520
}

website/versioned_docs/version-0.85/appearance.md

Lines changed: 37 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; import con
99
import {Appearance} from 'react-native';
1010
```
1111

12-
The `Appearance` module exposes information about the user's appearance preferences, such as their preferred color scheme (light or dark).
12+
The `Appearance` module exposes information about the user's appearance preferences, such as their preferred system color scheme (light or dark).
1313

1414
#### Developer notes
1515

@@ -53,7 +53,26 @@ if (colorScheme === 'dark') {
5353
}
5454
```
5555

56-
Although the color scheme is available immediately, this may change (e.g. scheduled color scheme change at sunrise or sunset). Any rendering logic or styles that depend on the user preferred color scheme should try to call this function on every render, rather than caching the value. For example, you may use the [`useColorScheme`](usecolorscheme) React hook as it provides and subscribes to color scheme updates, or you may use inline styles rather than setting a value in a `StyleSheet`.
56+
Although the color scheme is available immediately, this may change when not overridden via `setColorScheme()` (e.g. scheduled color scheme change at sunrise or sunset). Any rendering logic or styles that depend on the user preferred color scheme should try to call this function on every render, rather than caching the value.
57+
58+
**Recommended:** Use the [`useColorScheme`](usecolorscheme) hook.
59+
60+
### App-level overriding
61+
62+
`setColorScheme()` overrides the color scheme at the application level — it does not affect the system setting or other applications. Passing `'unspecified'` removes any override, restoring the system preference.
63+
64+
```mermaid
65+
flowchart TD
66+
USC["useColorScheme()"] --> GCS["getColorScheme()"]
67+
GCS --> DEC{App override?}
68+
DEC -- "NO / reset via setColorScheme('unspecified')" --> SYS["System preference\n'light' or 'dark'"]
69+
DEC -- "YES — setColorScheme('light' | 'dark')" --> OVR["'light' or 'dark' (static)"]
70+
71+
classDef fn fill:#dce8f8,stroke:#4a90d9,color:#1a1a1a
72+
classDef out fill:#f0f4f8,stroke:#8faabb,color:#1a1a1a
73+
class USC,GCS fn
74+
class OVR,SYS out
75+
```
5776

5877
---
5978

@@ -64,42 +83,37 @@ Although the color scheme is available immediately, this may change (e.g. schedu
6483
### `getColorScheme()`
6584

6685
```tsx
67-
static getColorScheme(): 'light' | 'dark' | null;
86+
static getColorScheme(): 'light' | 'dark' | 'unspecified' | null;
6887
```
6988

70-
Indicates the current user preferred color scheme. The value may be updated later, either through direct user action (e.g. theme selection in device settings or application-level selected user interface style via `setColorScheme`) or on a schedule (e.g. light and dark themes that follow the day/night cycle).
89+
Returns the active color scheme. The value may be updated later, either through direct user action (e.g. theme selection in device settings or application-level selected user interface style via `setColorScheme`) or on a schedule (e.g. light and dark themes that follow the day/night cycle).
7190

72-
Supported color schemes:
91+
Return values:
7392

74-
- `'light'`: The user prefers a light color theme.
75-
- `'dark'`: The user prefers a dark color theme.
76-
- `null`: The user has not indicated a preferred color theme.
93+
- `'light'`: The light color scheme is applied.
94+
- `'dark'`: The dark color scheme is applied.
95+
- `'unspecified'`: **_Never returned_** (incorrectly typed).
96+
- `null`: May be returned if the native Appearance module is not available.
7797

78-
See also: `useColorScheme` hook.
79-
80-
:::note
81-
`getColorScheme()` will always return `light` when debugging with Chrome.
82-
:::
98+
See also: [`useColorScheme`](usecolorscheme) (hook).
8399

84100
---
85101

86102
### `setColorScheme()`
87103

88104
```tsx
89-
static setColorScheme('light' | 'dark' | null): void;
105+
static setColorScheme('light' | 'dark' | 'unspecified'): void;
90106
```
91107

92-
Force the application to always adopt a light or dark interface style. The default value is `null` which causes the application to inherit the system's interface style. If you assign a different value, the new style applies to the application and all native elements within the application (Alerts, Pickers etc).
108+
Forces the application to always adopt a light or dark interface style. The change applies to the application and all native elements within it (Alerts, Pickers, etc.).
93109

94-
Supported color schemes:
110+
This is an app-level override — it does not affect the system's selected interface style or any style set in other applications.
95111

96-
- `light`: Apply light user interface style.
97-
- `dark`: Apply dark user interface style.
98-
- null: Follow the system's interface style.
112+
Supported values:
99113

100-
:::note
101-
The change will not affect the system's selected interface style or any style set in other applications.
102-
:::
114+
- `'light'`: Apply light color scheme.
115+
- `'dark'`: Apply dark color scheme.
116+
- `'unspecified'`: Follow the system color scheme (removes any override).
103117

104118
---
105119

@@ -111,4 +125,4 @@ static addChangeListener(
111125
): NativeEventSubscription;
112126
```
113127

114-
Add an event handler that is fired when appearance preferences change.
128+
Add an event handler that is fired when appearance preferences change. On iOS and Android, the `colorScheme` value in the callback is always `'light'` or `'dark'`.

website/versioned_docs/version-0.85/usecolorscheme.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@ title: useColorScheme
77
import {useColorScheme} from 'react-native';
88
```
99

10-
The `useColorScheme` React hook provides and subscribes to color scheme updates from the [`Appearance`](appearance) module. The return value indicates the current user preferred color scheme. The value may be updated later, either through direct user action (e.g. theme selection in device settings) or on a schedule (e.g. light and dark themes that follow the day/night cycle).
10+
The `useColorScheme` React hook provides and subscribes to color scheme updates from the [`Appearance`](appearance) module. The return value indicates the active color scheme. The value may be updated later, either through direct user action (e.g. theme selection in device settings or application-level selected user interface style via [`setColorScheme`](appearance#setcolorscheme)) or on a schedule (e.g. light and dark themes that follow the day/night cycle).
1111

12-
### Supported color schemes
12+
### Return values
1313

14-
- `"light"`: The user prefers a light color theme.
15-
- `"dark"`: The user prefers a dark color theme.
16-
- `null`: The user has not indicated a preferred color theme.
14+
- `'light'`: The light color scheme is applied.
15+
- `'dark'`: The dark color scheme is applied.
16+
- `'unspecified'`: **_Never returned_** (incorrectly typed).
17+
- `null`: May be returned if the native Appearance module is not available.
1718

1819
---
1920

0 commit comments

Comments
 (0)