-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.tsx
92 lines (86 loc) · 2.41 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import React, { useContext } from "react";
import { SafeAreaProvider } from "react-native-safe-area-context";
import { DefaultTheme, NavigationContainer } from "@react-navigation/native";
import { createNativeStackNavigator } from "@react-navigation/native-stack";
import { AppwriteProvider, AppwriteContext } from "./appwrite/Context";
//screens
import Home from "./screens/Home";
import Tasks from "./screens/Tasks";
import Login from "./screens/Login";
import Signup from "./screens/Signup";
import Loading from "./screens/Loading";
const Stack = createNativeStackNavigator();
const Navigation = () => {
const { appwrite, loggedIn, setLoggedIn } = useContext(AppwriteContext);
const [loading, setLoading] = React.useState(true);
React.useEffect(() => {
//check if user is logged in using getCurrentUser method
appwrite
.getCurrentUser()
.then((response) => {
setLoading(false);
if (response) {
setLoggedIn(true);
}
})
.catch((e) => {
console.log(e);
setLoading(false);
setLoggedIn(false);
});
}, []);
const MyTheme = {
...DefaultTheme,
colors: {
...DefaultTheme.colors,
background: "#F2F2F2",
},
};
return (
<NavigationContainer theme={MyTheme}>
<Stack.Navigator screenOptions={{ headerShown: false }}>
{loading ? (
<Stack.Screen name="Loading" component={Loading} />
) : loggedIn ? (
<>
<Stack.Screen
options={{ animation: "fade", gestureEnabled: false }}
name="Home"
component={Home}
/>
<Stack.Screen
options={{ animation: "slide_from_left" }}
name="Tasks"
component={Tasks}
/>
</>
) : (
<>
<Stack.Screen
options={{ animation: "fade", gestureEnabled: false }}
name="Login"
component={Login}
/>
<Stack.Screen
options={{ animation: "fade", gestureEnabled: false }}
name="Signup"
component={Signup}
/>
</>
)}
</Stack.Navigator>
</NavigationContainer>
);
};
const App = () => {
return (
<>
<AppwriteProvider>
<SafeAreaProvider>
<Navigation />
</SafeAreaProvider>
</AppwriteProvider>
</>
);
};
export default App;