-
Notifications
You must be signed in to change notification settings - Fork 1
/
App.tsx
47 lines (43 loc) · 1.59 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
import React, { useEffect, useState } from "react";
import { StatusBar } from "expo-status-bar";
import { useColorScheme } from "react-native";
import { createNativeStackNavigator } from "@react-navigation/native-stack";
import * as SecureStore from "expo-secure-store";
import { NavigationContainer } from "@react-navigation/native";
import { Provider as PaperProvider } from "react-native-paper";
import { HomeScreen, LoginScreen as LoginScreen } from "./screens";
import { AuthContext } from "./auth/AuthContext";
import { CombinedDarkTheme, CombinedDefaultTheme } from "./theme";
const Stack = createNativeStackNavigator();
export default function App() {
const scheme = useColorScheme();
const [token, setToken] = useState("");
const theme = scheme === "dark" ? CombinedDarkTheme : CombinedDefaultTheme;
useEffect(() => {
SecureStore.getItemAsync("userToken")
.then((userToken) => {
setToken(userToken || "");
})
.catch((e) => console.log({ e }));
}, []);
return (
<PaperProvider theme={theme}>
<NavigationContainer theme={theme}>
<StatusBar style="auto" />
<AuthContext.Provider value={{ token, setToken }}>
<Stack.Navigator>
{token ? (
<Stack.Screen name="Home" component={HomeScreen} />
) : (
<Stack.Screen
name="Login"
options={{ title: "Login / Register" }}
component={LoginScreen}
/>
)}
</Stack.Navigator>
</AuthContext.Provider>
</NavigationContainer>
</PaperProvider>
);
}