-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.tsx
69 lines (67 loc) · 2.16 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
import React, { useEffect, useState } from "react";
import { preventAutoHideAsync, hideAsync } from "expo-splash-screen";
import { NavigationContainer } from "@react-navigation/native";
import { useFonts } from "expo-font";
import { AntDesign } from "@expo/vector-icons";
import { defaultTheme } from "./styles/theme";
import { ThemeProvider } from "styled-components/native";
import { RecoilRoot } from "recoil";
import Router from "./src/router/Router";
import initializeFirebase from "firebases/initializeFirebase";
import UserUidContainer from "containers/auths/UserUidContainer";
import { UserCredential } from "firebase/auth";
import {
SimulatorNotificationError,
initializePushNotification,
setNotificationHandler,
} from "notifications/notification";
import { saveUserExpoNotificationToken } from "firebases/databases/users";
import { getDatabase, ref } from "firebase/database";
preventAutoHideAsync();
setNotificationHandler();
export default function App() {
const [fontsLoaded] = useFonts(AntDesign.font);
const [user, setUser] = useState<UserCredential>(null);
useEffect(() => {
const initialize = async () => {
let user;
try {
user = await initializeFirebase(); // initialize firebase
setUser(user);
} catch (e) {
alert("오류가 발생했습니다. 다시 시도해 주세요.");
}
try {
const token = await initializePushNotification();
if (token && user) {
// TODO:: make notification listener hooks
await saveUserExpoNotificationToken(
ref(getDatabase()),
user.user.uid,
token.data
);
}
} catch (error) {
if (error instanceof SimulatorNotificationError) {
console.log("run on simulator");
} else {
console.log(error);
}
}
};
initialize();
}, []);
if (fontsLoaded && user) {
hideAsync();
return (
<RecoilRoot>
<UserUidContainer uid={user?.user.uid} />
<ThemeProvider theme={defaultTheme}>
<NavigationContainer>
<Router />
</NavigationContainer>
</ThemeProvider>
</RecoilRoot>
);
}
}