-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
69 lines (61 loc) · 1.85 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
import React, { useState, useEffect } from 'react';
import { AsyncStorage } from 'react-native';
import { AppLoading } from 'expo';
import { Asset } from "expo-asset";
import * as Font from "expo-font";
import { Ionicons } from '@expo/vector-icons';
import { InMemoryCache } from "apollo-cache-inmemory";
import { persistCache } from "apollo-cache-persist";
import ApolloClient from "apollo-boost";
import { ThemeProvider } from "styled-components";
import { ApolloProvider } from "react-apollo-hooks";
import apolloClientOptions from "./apollo";
import styles from './styles';
import NavController from "./components/NavController";
import { AuthProvider } from "./AuthContext";
export default function App() {
const [loaded, setLoaded] = useState(false);
const [client, setClient] = useState(null);
const [isLoggedIn, setIsLoggedIn] = useState(null);
const preLoad = async() => {
try {
await Font.loadAsync({
...Ionicons.font
});
await Asset.loadAsync([require("./assets/logo.png")]);
const cache = new InMemoryCache();
await persistCache({
cache,
storage: AsyncStorage
});
const client = new ApolloClient({
cache,
...apolloClientOptions
});
const isLoggedIn = await AsyncStorage.getItem("isLoggedIn");
if (!isLoggedIn || isLoggedIn === "false") {
setIsLoggedIn(false);
} else {
setIsLoggedIn(true);
}
setLoaded(true);
setClient(client);
} catch (e) {
console.log(e);
}
}
useEffect(() => {
preLoad()
}, [])
return loaded && client && isLoggedIn !== null ? (
<ApolloProvider client={client}>
<ThemeProvider theme={styles}>
<AuthProvider isLoggedIn={isLoggedIn}>
<NavController />
</AuthProvider>
</ThemeProvider>
</ApolloProvider>
) : (
<AppLoading />
)
}