-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathApp.js
49 lines (44 loc) · 1.58 KB
/
App.js
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
import React, {useEffect} from 'react'
import {StatusBar} from 'react-native'
import {ApplicationProvider, IconRegistry} from '@ui-kitten/components'
import {EvaIconsPack} from '@ui-kitten/eva-icons'
import {mapping, light, dark} from '@eva-design/eva'
import {AppNavigator} from './app/components'
import {ThemeContext, BackgroundContext} from './app/context'
import SyncStorage from 'sync-storage'
const themes = {light, dark}
const App = () => {
const [theme, setTheme] = React.useState('light')
const [background, setBackground] = React.useState(false)
const currentTheme = themes[theme]
const toggleTheme = () => {
const nextTheme = theme === 'light' ? 'dark' : 'light'
setTheme(nextTheme)
}
const toggleBackground = () => {
const nextBackground = background ? false : true
setBackground(nextBackground)
}
useEffect(() => {
;(async () => {
await SyncStorage.init()
SyncStorage.get('theme') && setTheme(SyncStorage.get('theme'))
SyncStorage.get('background') &&
setBackground(JSON.parse(SyncStorage.get('background')))
})()
}, [])
return (
<>
<StatusBar backgroundColor={theme === 'light' ? '#E4E9F2' : '#222B45'} />
<IconRegistry icons={EvaIconsPack} />
<ThemeContext.Provider value={{theme, toggleTheme}}>
<BackgroundContext.Provider value={{background, toggleBackground}}>
<ApplicationProvider mapping={mapping} theme={currentTheme}>
<AppNavigator />
</ApplicationProvider>
</BackgroundContext.Provider>
</ThemeContext.Provider>
</>
)
}
export default App