-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathApp.tsx
More file actions
156 lines (141 loc) · 5.11 KB
/
App.tsx
File metadata and controls
156 lines (141 loc) · 5.11 KB
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
import React, { useEffect } from "react";
import "react-native-gesture-handler";
import { RecoilRoot, useSetRecoilState } from "recoil";
import messaging from "@react-native-firebase/messaging";
import { NavigationContainer } from "@react-navigation/native";
import PushNotification from "react-native-push-notification";
import Snackbar from "react-native-snackbar";
import { ToastAndroid } from "react-native";
import Toast from "react-native-toast-message";
// components
import BottomNavigator from "./components/BottomNavigator/BottomNavigator";
// [ADMIN] components
import AdminRightNavigation from "./components/_admin/_AdminRightNavigation/AdminRightNavigation";
import { Container } from "./styles/commonStyles";
import { Dimensions } from "react-native";
import { userFcmToken } from "./recoil/member/member";
// type RootStackParamList = {
// Home: undefined;
// Search: {
// id: number;
// };
// Mypage: undefined;
// };
const windowHeight = Dimensions.get("window").height;
const App = () => {
const setFCMToken = useSetRecoilState(userFcmToken);
Snackbar.LENGTH_LONG; // 또는 LENGTH_LONG 설정
// Snackbar.Color("#333"); // 스낵바 배경색 설정
// Snackbar.setActionTextColor("#f0e7d9"); // 액션 텍스트 색상 설정
// Snackbar = () => {
// 스낵바 액션 버튼 클릭 시 실행할 동작
// Snackbar.dismiss();
// });
useEffect(() => {
PushNotification.createChannel(
{
channelId: "opentheDoor", // 알림 채널 ID
channelName: "opentheDoor", // 알림 채널 이름
channelDescription: "opentheDoor 알림 채널", // 알림 채널 설명
soundName: "default", // 기본 알림 소리
importance: 4, // 중요도 설정
vibrate: true, // 진동 여부
},
created => console.log(`CreateChannel returned '${created}'`), // 콜백으로 채널 생성 성공 여부를 로그에 출력
);
}, []);
const getFcmToken = async () => {
const fcmToken = await messaging().getToken();
setFCMToken(fcmToken);
console.log("[FCM Token] ", fcmToken);
};
// firebase
messaging().setBackgroundMessageHandler(async remoteMessage => {
console.log("[Background Remote Message]", remoteMessage);
console.log("데이터 확인용", remoteMessage.notification);
// Toast.show({
// type: "info",
// text1: remoteMessage.data?.title || "opentheDoor",
// text2: remoteMessage.data?.body || "읽지 않은 알림이 있습니다.",
// visibilityTime: 5000, // 5초
// autoHide: true,
// topOffset: 30,
// bottomOffset: 40,
// });
PushNotification.localNotification({
title: remoteMessage.notification?.title || "opentheDoor",
message: remoteMessage.notification?.body || "",
channelId: "opentheDoor",
channelName: "opentheDoor",
playSound: true,
soundName: "default",
});
});
useEffect(() => {
getFcmToken();
const unsubscribe = messaging().onMessage(async remoteMessage => {
console.log(
"[Remote Message] ",
JSON.stringify(remoteMessage.data?.body),
);
////////////////후보 1 하얀 알림/////////////////////////////
// setTimeout(() => {
// Toast.show({
// type: "info",
// text1: remoteMessage.data?.title || "opentheDoor",
// text2: remoteMessage.data?.body || "읽지 않은 알림이 있습니다.",
// visibilityTime: 5000, // 5초
// autoHide: true,
// topOffset: 30,
// bottomOffset: 40,
// });
// }, 1500);
/////일반 android toast (지루한 디자인)////
// ToastAndroid.show(
// remoteMessage.data?.body || "Default Message",
// ToastAndroid.LONG,
// );
///////아래는 됩니다///////////////////////////////
///////push 알림///////////////////////////////////
// Snackbar.show({
// // title: remoteMessage.data?.title || "Default Title",
// text: remoteMessage.data?.body || "Default Message",
// duration: Snackbar.LENGTH_LONG, // 또는 LENGTH_SHORT
// action: {
// text: "닫기",
// textColor: "grey",
// onPress: () => {
// Snackbar.dismiss();
// },
// },
// // position: "absolute",
// // top: 0,
// // marginBottom: (windowHeight / 100) * 94,
// });
// });
//////////////////여기까지/////////////////////////////
////////////////////////////////////////////
PushNotification.localNotification({
title: remoteMessage.data?.title || "opentheDoor",
message: remoteMessage.data?.body || "",
channelId: "opentheDoor",
playSound: true,
soundName: "default",
});
});
return unsubscribe;
}, []);
return (
<RecoilRoot>
<Container>
<NavigationContainer>
<BottomNavigator />
<Toast />
{/* FIXME - 어드민 기능 사용 (주석 필수) */}
{/* <AdminRightNavigation /> */}
</NavigationContainer>
</Container>
</RecoilRoot>
);
};
export default App;