-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.tsx
89 lines (76 loc) · 2.78 KB
/
App.tsx
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/**
* This component is the top dog. This is the component that renders when running the code.
* @category BIG
* @module App
*/
import React, { useState } from 'react'
import 'react-native-gesture-handler'
import AppLoading from 'expo-app-loading'
import { Provider } from '@nationskollen/sdk'
import { PushTokenProvider } from './components/PushTokenContext'
import AsyncStorage from '@react-native-async-storage/async-storage'
import { LanguageContextProvider } from './translate/LanguageContext'
import { setCustomText, setCustomTextInput } from 'react-native-global-props'
import { DarkTheme, LightTheme, ThemeProvider, Theme } from './components/ThemeContext'
import { useFonts, Roboto_700Bold, Roboto_400Regular } from '@expo-google-fonts/roboto'
import Footer from './components/Footer/Footer'
const App = () => {
const [initialTheme, setInitialTheme] = useState<Theme | null>(null)
const [initialLanguageKey, setInitialLanguageKey] = useState<number>(1)
const [isReady, setIsReady] = useState(false)
const [loaded] = useFonts({
Roboto_400Regular,
Roboto_700Bold,
})
// We have to to wait for the app to load the custom font before we render it
if (!loaded) {
return null
}
const customTextProps = {
style: {
fontFamily: 'Roboto_400Regular',
},
}
setCustomText(customTextProps)
setCustomTextInput(customTextProps)
if (!isReady) {
return (
<AppLoading
startAsync={async () => {
const theme = await AsyncStorage.getItem('savedTheme')
const language = await AsyncStorage.getItem('savedLanguage')
if (!theme) {
setInitialTheme(LightTheme)
}
const isDark = JSON.parse(theme)
setInitialTheme(isDark ? DarkTheme : LightTheme)
if (language) {
setInitialLanguageKey(parseInt(language))
}
}}
onFinish={() => setIsReady(true)}
autoHideSplash={true}
onError={console.warn}
/>
)
}
return (
<Provider
config={{
development: true,
useWebSockets: true,
customHostName: 'nationskollen-staging.engstrand.nu',
useHTTPS: true,
}}
>
<ThemeProvider initialTheme={initialTheme}>
<LanguageContextProvider initialLanguage={initialLanguageKey}>
<PushTokenProvider>
<Footer />
</PushTokenProvider>
</LanguageContextProvider>
</ThemeProvider>
</Provider>
)
}
export default App