@@ -4,11 +4,10 @@ import {
4
4
createNativeStackNavigator ,
5
5
NativeStackScreenProps ,
6
6
} from "@react-navigation/native-stack" ;
7
- import { ReactNode , useState } from "react" ;
7
+ import { ReactNode , useEffect , useState } from "react" ;
8
8
import {
9
9
Appearance ,
10
10
Text as BaseText ,
11
- ColorSchemeName ,
12
11
Modal ,
13
12
Platform ,
14
13
StyleProp ,
@@ -101,6 +100,7 @@ const Button = ({
101
100
) ;
102
101
} ;
103
102
103
+ const SCHEMES = [ "system" , "light" , "dark" ] ;
104
104
const STYLES : SystemBarStyle [ ] = [ "auto" , "light" , "dark" ] ;
105
105
106
106
type StackParamList = {
@@ -160,11 +160,18 @@ export const HomeScreen = ({
160
160
? { false : "#1c1c1f" , true : "#2b3e55" }
161
161
: { false : "#eeeef0" , true : "#ccd8e5" } ;
162
162
163
+ const [ schemeIndex , setSchemeIndex ] = useState ( 0 ) ;
163
164
const [ styleIndex , setStyleIndex ] = useState ( 0 ) ;
164
165
const [ statusBarHidden , setStatusBarHidden ] = useState ( false ) ;
165
166
const [ navigationBarHidden , setNavigationBarHidden ] = useState ( false ) ;
166
167
const [ reactNativeModalVisible , setReactNativeModalVisible ] = useState ( false ) ;
167
168
169
+ useEffect ( ( ) => {
170
+ const value = SCHEMES [ schemeIndex ] ;
171
+ const scheme = value === "light" || value === "dark" ? value : null ;
172
+ Appearance . setColorScheme ( scheme ) ;
173
+ } , [ schemeIndex ] ) ;
174
+
168
175
const closeReactNativeModal = ( ) => {
169
176
setReactNativeModalVisible ( false ) ;
170
177
} ;
@@ -182,10 +189,10 @@ export const HomeScreen = ({
182
189
< Title > Theme</ Title >
183
190
184
191
< SegmentedControl
185
- values = { [ "light" , "dark" ] satisfies ColorSchemeName [ ] }
186
- selectedIndex = { dark ? 1 : 0 }
192
+ values = { SCHEMES }
193
+ selectedIndex = { schemeIndex }
187
194
onValueChange = { ( value ) => {
188
- Appearance . setColorScheme ( value as ColorSchemeName ) ;
195
+ setSchemeIndex ( SCHEMES . indexOf ( value ) ) ;
189
196
} }
190
197
/>
191
198
0 commit comments