-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.tsx
126 lines (116 loc) · 3.75 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
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
import * as React from 'react';
import {LinkingOptions, NavigationContainer} from '@react-navigation/native';
import {
QueryCache,
QueryClient,
QueryClientProvider,
useQueryErrorResetBoundary,
} from '@tanstack/react-query';
import {UserContextProvider} from './app/contexts/UserContext';
import dynamicLinks from '@react-native-firebase/dynamic-links';
import AuthRouter from './app/router/AuthRouter';
import messaging from '@react-native-firebase/messaging';
import useApiError from './app/hooks/handlers/useApiError';
import {ErrorBoundary} from 'react-error-boundary';
import FallbackUI from './app/components/handlers/fallbackUI';
import Toast from 'react-native-toast-message';
import notifee, {AndroidImportance} from '@notifee/react-native';
import SplashScreen from 'react-native-splash-screen';
import {handleDynamicLink, updateAppVersion} from './app/utils/device';
import {Linking} from 'react-native';
import {RootStackParamList} from './app/types/router';
export const App = () => {
const {handleError} = useApiError();
const queryClient = new QueryClient({
defaultOptions: {
mutations: {onError: handleError},
queries: {
throwOnError: true,
retry: false,
},
},
queryCache: new QueryCache({
onError: handleError,
}),
});
const {reset} = useQueryErrorResetBoundary();
const appVersionCheck = React.useCallback(() => updateAppVersion(), []);
React.useEffect(() => {
const foreGroundMessage = async (title, body) => {
await notifee.requestPermission();
const channelId = await notifee.createChannel({
id: 'MoA',
name: '모아',
importance: AndroidImportance.HIGH,
});
await notifee.displayNotification({
title,
body,
android: {
channelId,
pressAction: {
id: 'MoA',
},
},
});
};
// 추후 테스트후 변경할 것
// notifee.onForegroundEvent(({type, detail}) => {
// const {
// notification: {title, body},
// } = detail;
// switch (type) {
// case EventType.PRESS:
// console.log('User pressed notification', detail.notification);
// break;
// }
// });
const unsubscribe = messaging().onMessage(async remoteMessage => {
const {
notification: {body, title},
data,
} = remoteMessage;
foreGroundMessage(title, body);
});
// const unsubscribe2 = dynamicLinks().onLink(handleDynamicLink);
// When the component is unmounted, remove the listener
// return () => unsubscribe();
// 앱 배포 URL 적용 후, 코드 활성화 예정
// appVersionCheck();
SplashScreen.hide();
return unsubscribe;
}, []);
// const DEEPLINK_PREFIX_URL = ['giftMoA://', 'https://giftmoa.page.link'];
// const deepLinksConfig = {
// initialRouteName: 'Home',
// screens: {
// // FundDetailScreen: 'FundDetail/:id',
// // MyFundingScreen: 'MyFunding',
// // MyInquiries: 'MyInquiries',
// // MyOrderDetailScreen: 'MyOrder/:id',
// },
// };
// const linking: LinkingOptions<RootStackParamList> = {
// prefixes: DEEPLINK_PREFIX_URL,
// config: deepLinksConfig,
// async getInitialURL() {
// // 딥링크를 이용해서 앱이 오픈되었을 때
// const url = await Linking.getInitialURL();
// if (url != null) {
// return url;
// }
// },
// };
return (
<QueryClientProvider client={queryClient}>
<NavigationContainer>
<ErrorBoundary onReset={reset} FallbackComponent={FallbackUI}>
<UserContextProvider>
<AuthRouter />
</UserContextProvider>
</ErrorBoundary>
</NavigationContainer>
<Toast />
</QueryClientProvider>
);
};