-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.tsx
66 lines (59 loc) · 1.94 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
import React, { useState, useEffect } from "react";
import { SafeAreaProvider } from "react-native-safe-area-context";
import useCachedResources from "./hooks/useCachedResources";
import useColorScheme from "./hooks/useColorScheme";
import Navigation from "./navigation";
import AppContext from "./components/AppContext";
import { getItem } from "./storage";
// Import the functions you need from the SDKs you need
import { User } from "firebase/auth";
import { AuthUserContext } from "./contexts/AuthContext";
import { fireBaseAuth } from "./firebase/config";
import { StatusBar } from "./components/Themed";
const auth = fireBaseAuth.getAuth();
// Your web app's Firebase configuration
// For Firebase JS SDK v7.20.0 and later, measurementId is optional
export default function App() {
const isLoadingComplete = useCachedResources();
const colorScheme = useColorScheme();
const [scheme, setScheme] = useState(colorScheme);
const [user, setUser] = useState(null as User | null);
const [username, setUserName] = useState(null as string | null);
useEffect(() => {
getItem("userToken").then(() => {});
}, []);
useEffect(() => {
getItem("userTheme").then((result) => {
if (result === "light" || result === "dark") {
setScheme(result);
}
});
}, []);
useEffect(() => {
auth.onAuthStateChanged((user) => {
setUser(user);
if (!user) {
setUserName(null);
}
});
}, []);
const userSettings = {
scheme: scheme,
setScheme: setScheme,
};
const authContext = { user, setUser, auth, username, setUserName };
if (!isLoadingComplete) {
return null;
} else {
return (
<SafeAreaProvider>
<AppContext.Provider value={userSettings}>
<AuthUserContext.Provider value={authContext}>
<Navigation colorScheme={scheme} />
<StatusBar />
</AuthUserContext.Provider>
</AppContext.Provider>
</SafeAreaProvider>
);
}
}