-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
88 lines (79 loc) · 2.52 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import { NavigationContainer } from "@react-navigation/native";
import { createNativeStackNavigator } from "@react-navigation/native-stack";
import React, { useState, useEffect } from "react";
import { GestureHandlerRootView } from "react-native-gesture-handler";
import auth from "@react-native-firebase/auth";
import LoginScreen from "./src/screens/login";
import HomeScreen from "./src/screens/home";
import AsyncStorage from "@react-native-async-storage/async-storage";
import Onboarding from "./src/screens/onboarding";
import CreateTaskScreen from "./src/screens/createTask";
const Stack = createNativeStackNavigator();
export default function App() {
const [viewedOnboarding, setViewedOnboarding] = useState(false);
const [initializing, setInitializing] = useState(true);
const [user, setUser] = useState();
function onAuthStateChanged(user) {
setUser(user);
if (initializing) setInitializing(false);
}
useEffect(() => {
const subscriber = auth().onAuthStateChanged(onAuthStateChanged);
return subscriber;
}, []);
const checkOnboarding = async () => {
try {
const value = await AsyncStorage.getItem("@viewedOnboarding");
if (value !== null) {
setViewedOnboarding(true);
}
} catch (e) {
console.log("Error @checkOnboarding: ", e);
}
};
useEffect(() => {
checkOnboarding();
}, []);
if (initializing) return null;
if (!user) {
return (
<GestureHandlerRootView style={{ flex: 1 }}>
<NavigationContainer>
<Stack.Navigator>
{viewedOnboarding ? null : (
<Stack.Screen
name="Onboarding"
component={Onboarding}
options={{ headerShown: false }}
/>
)}
<Stack.Screen
name="Login"
component={LoginScreen}
options={{ headerShown: false }}
/>
</Stack.Navigator>
</NavigationContainer>
</GestureHandlerRootView>
);
} else {
return (
<GestureHandlerRootView style={{ flex: 1 }}>
<NavigationContainer>
<Stack.Navigator>
<Stack.Screen
name="Home"
component={HomeScreen}
options={{ headerShown: false }}
/>
<Stack.Screen
name="CreateTask"
component={CreateTaskScreen}
options={{ headerShown: false }}
/>
</Stack.Navigator>
</NavigationContainer>
</GestureHandlerRootView>
);
}
}