-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
74 lines (63 loc) · 2.47 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import { NavigationContainer } from "@react-navigation/native";
import { GestureHandlerRootView } from "react-native-gesture-handler";
import { View } from "react-native";
import { useEffect, useState, useCallback } from "react";
import * as SplashScreen from "expo-splash-screen";
import { navigationRef } from "./app/navigation/rootNavigation";
import navigationTheme from "./app/navigation/navigationTheme";
import AppNavigator from "./app/navigation/AppNavigator";
import OfflineNotice from "./app/components/OfflineNotice";
import AuthNavigator from "./app/navigation/AuthNavigator";
import AuthContext from "./app/auth/context";
import authStorage from "./app/auth/storage";
import logger from "./app/utility/logger";
logger.start();
SplashScreen.preventAutoHideAsync();
export default function App() {
const [user, setUser] = useState();
const [isReady, setIsReady] = useState(false);
const restoreUser = async () => {
const user = await authStorage.getUser();
if (user) return setUser(user);
};
const prepare = async () => {
await restoreUser();
setIsReady(true);
};
useEffect(() => {
prepare();
}, []);
const onLayoutRootView = useCallback(async () => {
if (isReady) {
// This tells the splash screen to hide immediately! If we call this after
// `setIsReady`, then we may see a blank screen while the app is
// loading its initial state and rendering its first pixels. So instead,
// we hide the splash screen once we know the root view has already
// performed layout.
await SplashScreen.hideAsync();
}
}, [isReady]);
if (!isReady) {
return null;
}
return (
/*
FIXME: FIXED upgrade the expo to @latest("^51.0.16")
The following packages should be updated for best compatibility with the installed expo version:
[email protected] - expected version: ~51.0.17
Your project may not work correctly until you install the expected versions of the packages.
*/
//GestureHandlerRootView removed from ListItem.js.
//Swipeable component was wrapped inside.
<View style={{ flex: 1 }} onLayout={onLayoutRootView}>
<AuthContext.Provider value={{ user, setUser }}>
<OfflineNotice />
<GestureHandlerRootView style={{ flex: 1 }}>
<NavigationContainer ref={navigationRef} theme={navigationTheme}>
{user ? <AppNavigator /> : <AuthNavigator />}
</NavigationContainer>
</GestureHandlerRootView>
</AuthContext.Provider>
</View>
);
}