-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.tsx
More file actions
52 lines (46 loc) · 1.61 KB
/
App.tsx
File metadata and controls
52 lines (46 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import { StatusBar } from 'expo-status-bar';
import React, { useEffect, useMemo, useState } from 'react';
import { SafeAreaProvider } from 'react-native-safe-area-context';
//import {StatusBar as bar} from 'react-native'
import useCachedResources from './hooks/useCachedResources';
import useColorScheme from './hooks/useColorScheme';
import Navigation from './navigation';
import {AsyncStore as AsyncStorage} from './funcs/AsyncStore';
import { ThemeContext } from './navigation/context'
import Constants from 'expo-constants'
export default function App() {
const isLoadingComplete = useCachedResources();
const [colorScheme, setColorScheme] = useState<"light"|"dark">(useColorScheme());
useEffect(()=>{
const getData = async () => {
try {
const value = await AsyncStorage.getItem('theme') as "light" | "dark"
if(value) setColorScheme(value)
} catch(e) {
// error reading value
}
}
getData()
},[])
const status = useMemo(()=> {
return <StatusBar style = {colorScheme === "dark" ? "light":"dark"} backgroundColor = {colorScheme === "dark" ? "black" : "white"}/>
},[colorScheme])
const themeContext = useMemo(()=> ({
changeTheme: (val: "light" | "dark") => {
setColorScheme(val)
},
color: colorScheme
}),[colorScheme])
if (!isLoadingComplete) {
return null;
} else {
return (
<ThemeContext.Provider value = {themeContext} >
<SafeAreaProvider style = {{marginTop: Constants.statusBarHeight}}>
<Navigation colorScheme={colorScheme} />
{status}
</SafeAreaProvider>
</ThemeContext.Provider>
);
}
}