Commit 0f6e19a
Narrow ColorSchemeName, remove 'unspecified' from public API
Summary:
Splits the `ColorSchemeName` type to separate output values (`'light' | 'dark'`) from the setter input (`ColorSchemeOverride = 'light' | 'dark' | 'unspecified'`). This resolves a longstanding misalignment between what native returns and what the types promise.
This is paired with recent/proposed docs updates:
- react/react-native-website#5060
- react/react-native-website#5069
**Detailed changes**
`'unspecified'` is only meaningful as an input to `setColorScheme()` (meaning "follow the system default"). Neither iOS nor Android ever returns `'unspecified'` from `getColorScheme()` — when `setColorScheme('unspecified')` is called, the JS layer immediately re-queries `NativeAppearance.getColorScheme()` and caches the resolved system value instead.
New public types:
- `ColorSchemeName = 'light' | 'dark'`
- `ColorSchemeOverride = ColorSchemeName | 'unspecified'`
Updated signatures:
- `setColorScheme()`: `ColorSchemeOverride` (unchanged values, new named type)
**History of this API**
- The TurboModule spec originally typed these methods as plain `string` because codegen didn't support union types (T52919652).
- When support landed, D63681874 upgraded to `ColorSchemeName = 'light' | 'dark' | 'unspecified'` — a type-level cleanup that inadvertently widened return types to include `'unspecified'`, a value native never returns. This caused `$FlowFixMe` suppressions across downstream callers.
- D80705652 later aligned the `.d.ts` and fixed a bug where `setColorScheme('unspecified')` threw an incorrect invariant.
Changelog:
[General][Breaking] - `useColorScheme` now returns `'light' | 'dark' | null` (this was always the case, but is a breaking type change)
Differential Revision: D1025273871 parent d1cdce2 commit 0f6e19a
6 files changed
Lines changed: 76 additions & 38 deletions
File tree
- packages
- react-native
- Libraries/Utilities
- src/private/specs_DEPRECATED/modules
- rn-tester/js/examples/Appearance
Lines changed: 21 additions & 14 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
12 | | - | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
13 | 15 | | |
14 | 16 | | |
15 | 17 | | |
| |||
19 | 21 | | |
20 | 22 | | |
21 | 23 | | |
22 | | - | |
23 | | - | |
24 | | - | |
25 | | - | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
26 | 30 | | |
27 | | - | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
28 | 34 | | |
29 | 35 | | |
30 | 36 | | |
31 | 37 | | |
32 | | - | |
33 | | - | |
34 | | - | |
35 | | - | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
36 | 41 | | |
37 | | - | |
| 42 | + | |
38 | 43 | | |
39 | 44 | | |
40 | | - | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
41 | 48 | | |
42 | 49 | | |
43 | 50 | | |
44 | 51 | | |
45 | 52 | | |
46 | 53 | | |
47 | 54 | | |
48 | | - | |
49 | | - | |
| 55 | + | |
| 56 | + | |
50 | 57 | | |
51 | 58 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
12 | | - | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
13 | 17 | | |
14 | 18 | | |
15 | 19 | | |
16 | 20 | | |
17 | 21 | | |
18 | | - | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
19 | 27 | | |
20 | 28 | | |
21 | 29 | | |
| |||
56 | 64 | | |
57 | 65 | | |
58 | 66 | | |
59 | | - | |
| 67 | + | |
60 | 68 | | |
61 | 69 | | |
62 | 70 | | |
| |||
69 | 77 | | |
70 | 78 | | |
71 | 79 | | |
72 | | - | |
73 | | - | |
74 | | - | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
75 | 90 | | |
76 | 91 | | |
77 | 92 | | |
| |||
91 | 106 | | |
92 | 107 | | |
93 | 108 | | |
94 | | - | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
95 | 112 | | |
96 | | - | |
| 113 | + | |
97 | 114 | | |
98 | 115 | | |
99 | 116 | | |
100 | 117 | | |
101 | 118 | | |
102 | | - | |
103 | | - | |
104 | 119 | | |
105 | 120 | | |
106 | | - | |
| 121 | + | |
107 | 122 | | |
108 | 123 | | |
109 | 124 | | |
110 | 125 | | |
111 | 126 | | |
112 | 127 | | |
113 | | - | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
114 | 131 | | |
115 | 132 | | |
116 | 133 | | |
| |||
Lines changed: 8 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
23 | 31 | | |
24 | 32 | | |
25 | 33 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
| 7 | + | |
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| |||
1629 | 1629 | | |
1630 | 1630 | | |
1631 | 1631 | | |
| 1632 | + | |
| 1633 | + | |
1632 | 1634 | | |
1633 | 1635 | | |
1634 | 1636 | | |
1635 | 1637 | | |
1636 | | - | |
| 1638 | + | |
1637 | 1639 | | |
1638 | 1640 | | |
1639 | 1641 | | |
| |||
1856 | 1858 | | |
1857 | 1859 | | |
1858 | 1860 | | |
1859 | | - | |
| 1861 | + | |
| 1862 | + | |
1860 | 1863 | | |
1861 | 1864 | | |
1862 | 1865 | | |
| |||
4709 | 4712 | | |
4710 | 4713 | | |
4711 | 4714 | | |
4712 | | - | |
| 4715 | + | |
4713 | 4716 | | |
4714 | 4717 | | |
4715 | 4718 | | |
| |||
6070 | 6073 | | |
6071 | 6074 | | |
6072 | 6075 | | |
6073 | | - | |
| 6076 | + | |
6074 | 6077 | | |
6075 | 6078 | | |
6076 | 6079 | | |
| |||
6080 | 6083 | | |
6081 | 6084 | | |
6082 | 6085 | | |
6083 | | - | |
| 6086 | + | |
6084 | 6087 | | |
6085 | 6088 | | |
6086 | 6089 | | |
| |||
6336 | 6339 | | |
6337 | 6340 | | |
6338 | 6341 | | |
6339 | | - | |
| 6342 | + | |
6340 | 6343 | | |
6341 | 6344 | | |
6342 | 6345 | | |
Lines changed: 4 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | | - | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
16 | 18 | | |
17 | 19 | | |
18 | 20 | | |
19 | 21 | | |
20 | 22 | | |
21 | 23 | | |
22 | 24 | | |
23 | | - | |
| 25 | + | |
24 | 26 | | |
25 | 27 | | |
26 | 28 | | |
| |||
Lines changed: 4 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
21 | | - | |
| 21 | + | |
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
| |||
135 | 135 | | |
136 | 136 | | |
137 | 137 | | |
138 | | - | |
139 | | - | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
140 | 141 | | |
141 | 142 | | |
142 | 143 | | |
| |||
0 commit comments