-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.tsx
61 lines (57 loc) · 1.91 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
// React / Native / i18n import
import {
useEffect,
useRef, useState,
} from 'react'
import {
View,
} from 'react-native'
// Library
import Main from './src/Main'
import CreateStyledComponent from './src/libs/styledComponents'
import Translations from './src/lang/translations'
import DefaultValues from './src/defaultValues'
import { NativeControllerProvider, NativeController } from './src/libs/nativeController'
import { StorageProvider } from './src/libs/useStorage'
import { ThemeProvider } from './src/providers/ThemeProvider'
import { I18nProvider } from './src/providers/I18nProvider'
// Styled Components
const MainView = CreateStyledComponent(View,{
flex: 1,
alignItems: 'center',
justifyContent: 'center',
})
export default function App() {
// if all provider loaded, hide splash screen
const NativeControllerRef = useRef<NativeController>()
const [ loadedProviders, setLoadedProviders ] = useState({
I18nProvider: false,
ThemeProvider: false,
} as { [key:string]: boolean })
useEffect(()=>{
for (const provider in loadedProviders)
if (!loadedProviders[provider]) return
NativeControllerRef.current?.setAppIsReady(true)
},[ loadedProviders ])
return (
<MainView>
<StorageProvider defaultValues={DefaultValues}>
<NativeControllerProvider contextRef={NativeControllerRef}>
<I18nProvider translations={Translations}
onReady={ ()=>{ setLoadedProviders(current=>{
console.debug("I18n Provider loaded")
return {...current, I18nProvider: false}}) }
}>
<ThemeProvider
onReady={ ()=>{ setLoadedProviders(current=>{
console.debug("Theme Provider loaded")
return {...current, ThemeProvider: false}}) }
}>
<Main/>
</ThemeProvider>
</I18nProvider>
</NativeControllerProvider>
</StorageProvider>
</MainView>
)
}