-
Notifications
You must be signed in to change notification settings - Fork 2
/
App.tsx
93 lines (77 loc) · 2.19 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
93
import React, { useEffect, useState } from "react";
import { View, Text } from "react-native";
// REACT NAVIGATION
import { NavigationContainer } from "@react-navigation/native";
// UI KITTEN
import * as eva from "@eva-design/eva";
import { ApplicationProvider, IconRegistry } from "@ui-kitten/components";
import { EvaIconsPack } from "@ui-kitten/eva-icons";
// FIREBASE
import * as firebase from "firebase";
// import firebase from "./firebaseConfig";
// NAVIGATORS
import AuthNavigator from "./src/navigators/AuthNavigator";
import HomeNavigator from "./src/navigators/HomeNavigator";
// SCREENS
import SignUp from "./src/screens/Auth/SignUp";
// Optionally import the services that you want to use
//import "firebase/auth";
//import "firebase/database";
//import "firebase/firestore";
//import "firebase/functions";
//import "firebase/storage";
// Initialize Firebase
// For Firebase JS SDK v7.20.0 and later, measurementId is optional
// Get your firebaseConfig from the Firebase console
const firebaseConfig = {
apiKey: "",
authDomain: "",
projectId: "",
storageBucket: "",
messagingSenderId: "",
appId: "",
measurementId: "",
};
if (firebase.apps.length === 0) {
firebase.initializeApp(firebaseConfig);
}
const App = () => {
const [theme, setTheme] = React.useState<"light" | "dark">("light");
const toggleTheme = () => setTheme(theme === "light" ? "dark" : "light");
const [loaded, setLoaded] = useState(false);
const [loggedIn, setLoggedIn] = useState(false);
useEffect(() => {
firebase.auth().onAuthStateChanged(user => {
if (!user) {
setLoggedIn(false);
setLoaded(true);
} else {
setLoggedIn(true);
setLoaded(true);
}
});
}, []);
if (!loaded) {
return (
<View style={{ flex: 1, justifyContent: "center", alignItems: "center" }}>
<Text>Loading...</Text>
</View>
);
}
if (!loggedIn) {
return (
<NavigationContainer>
<ApplicationProvider {...eva} theme={eva[theme]}>
<IconRegistry icons={EvaIconsPack} />
<AuthNavigator />
</ApplicationProvider>
</NavigationContainer>
);
}
return (
<View style={{ flex: 1, justifyContent: "center", alignItems: "center" }}>
<Text>User is logged in</Text>
</View>
);
};
export default App;