-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
60 lines (49 loc) · 1.56 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
59
60
import "react-native-gesture-handler";
import { NavigationContainer } from "@react-navigation/native";
import AppLoading from "expo-app-loading";
import { useEffect, useState } from "react";
import { Theme } from "./app/components";
import useLoadAssets from "./app/hooks/useLoadAssets";
// import AuthNavigator from './app/navigation/AuthNavigator';
import AppNavigator from "./app/navigation/AppNavigator";
import { navigationRef } from "./app/navigation/rootNavigation";
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
ref={navigationRef}
{...{ initialState, onStateChange }}
>
{/* <AuthNavigator /> */}
<AppNavigator />
</NavigationContainer>
</Theme>
);
}