-
Notifications
You must be signed in to change notification settings - Fork 3
/
App.js
58 lines (48 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
50
51
52
53
54
55
56
57
58
import { NavigationContainer } from '@react-navigation/native';
import { AppLoading } from 'expo';
import React, { useEffect, useState } from 'react';
import { Theme } from './app/components';
import useLoadAssets from './app/hooks/useLoadAssets';
import AuthNavigator from './app/navigation/AuthNavigator';
import navigationTheme from './app/navigation/navigationTheme';
// import MainNavigator from './app/navigation/MainNavigator';
// import AppNavigator from './app/navigation/AppNavigator';
import cache from './app/utility/cache';
const PERSISTENCE_KEY = 'NAVIGATION_STATE';
export default function App() {
const [isReady, setIsReady] = useState(false);
const [initialState, setInitalState] = useState();
const { assetsLoaded, setAssetsLoaded, loadAssetsAsync } = useLoadAssets();
const restoreState = async () => {
try {
const state = (await cache.get(PERSISTENCE_KEY)) || undefined;
setInitalState(state);
} finally {
setIsReady(true);
}
if (!isReady) {
restoreState();
}
};
useEffect(() => {
restoreState();
}, [isReady]);
const onStateChange = (PERSISTENCE_KEY, state) => cache.store(PERSISTENCE_KEY, state);
if (!assetsLoaded || !isReady) {
return (
<AppLoading
startAsync={loadAssetsAsync}
onFinish={() => setAssetsLoaded(true)}
onError={console.warn}
/>
);
}
return (
<Theme>
<NavigationContainer {...{ initialState, onStateChange }} theme={navigationTheme}>
<AuthNavigator />
{/* <MainNavigator /> */}
</NavigationContainer>
</Theme>
);
}