-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
49 lines (42 loc) · 1.43 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
import React, { useState, useContext, createContext, useEffect } from "react";
import { useFonts } from "@use-expo/font";
import { AsyncStorage } from "react-native";
import { ThemeProvider } from "styled-components/native";
import { AppLoading } from "expo";
import { NavigationContainer } from "@react-navigation/native";
import AuthNavigation from "./app/navigation/AuthNavigation";
import RootNavigation from "./app/navigation/RootNavigation";
import theme from "./app/config/theme";
export const AuthContext = createContext("");
export default () => {
console.disableYellowBox = true;
const [userToken, setUserToken] = useState("");
const [loading, setLoading] = useState(true);
useEffect(() => {
const getToken = async () => {
try {
const userToken = await AsyncStorage.getItem("userToken");
if (userToken !== null) {
setUserToken(userToken);
}
} catch (err) {
console.log(err);
}
};
getToken();
setLoading(false);
});
const [fontsLoaded] = useFonts({
Poppins: require("./app/assets/fonts/Poppins.otf"),
});
if (loading || !fontsLoaded) return <AppLoading />;
return (
<ThemeProvider theme={theme}>
<AuthContext.Provider value={{ userToken, setUserToken }}>
<NavigationContainer>
{userToken ? <RootNavigation /> : <AuthNavigation />}
</NavigationContainer>
</AuthContext.Provider>
</ThemeProvider>
);
};