-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.tsx
77 lines (72 loc) · 2.6 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
import { StatusBar } from "react-native";
import { SafeAreaProvider } from "react-native-safe-area-context";
import { NavigationContainer } from "@react-navigation/native";
import { ThemeProvider } from "styled-components";
import { ApolloClient, InMemoryCache, ApolloProvider } from "@apollo/client";
import { getColorScheme } from "./src/helpers";
import useCachedResources from "./src/hooks/useCachedResources";
import useColorScheme from "./src/hooks/useColorScheme";
import { LoginStack, RootStack, TabsStack } from "./src/navigation";
import { AppLoader } from "./src/AppLoader";
import { useApolloClient } from "./src/hooks/useApolloClient";
import { useEffect, useState } from "react";
import AsyncStorage from "@react-native-async-storage/async-storage";
if (__DEV__) {
import("./ReactotronConfig");
}
export default function App() {
const showSplash = useCachedResources();
const colorScheme = useColorScheme();
const { theme, statusBarStyle } = getColorScheme("AUTOMATIC", colorScheme);
const { client, clearCache } = useApolloClient();
const [authToken, setAuthToken] = useState("");
// clearCache();
useEffect(() => {
const readCachedUser = async () => {
try {
const value = await AsyncStorage.getItem("@USER_AUTH_TOKEN");
if (value !== null) {
setAuthToken(value);
}
} catch (e) {
console.log("Custom Error(Not found user auth token): ", e);
}
};
readCachedUser();
}, []);
if (showSplash || !client) {
return <AppLoader></AppLoader>;
} else {
return (
<ApolloProvider client={client}>
<ThemeProvider theme={theme.colors}>
<SafeAreaProvider>
<NavigationContainer>
<StatusBar barStyle={statusBarStyle} />
<RootStack.Navigator
initialRouteName={authToken ? "Main" : "CreationModal"}
>
<RootStack.Group>
<RootStack.Screen
name="Main"
component={TabsStack}
options={{ headerShown: false }}
/>
</RootStack.Group>
<RootStack.Group screenOptions={{ presentation: "card" }}>
<RootStack.Screen
name="CreationModal"
options={{
headerShown: false,
}}
component={LoginStack}
/>
</RootStack.Group>
</RootStack.Navigator>
</NavigationContainer>
</SafeAreaProvider>
</ThemeProvider>
</ApolloProvider>
);
}
}