-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathApp.tsx
83 lines (74 loc) · 2.54 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
import React, {useEffect} from 'react';
import {Provider} from 'react-redux';
import store, {persistor} from './src/features/store';
import MainStack from './src/navigation';
import SplashScreen from 'react-native-splash-screen';
import FlashMessage from 'react-native-flash-message';
import {PersistGate} from 'redux-persist/integration/react';
import {QueryClient, QueryClientProvider} from '@tanstack/react-query';
import notifee, {AuthorizationStatus} from '@notifee/react-native';
import messaging, {
FirebaseMessagingTypes,
} from '@react-native-firebase/messaging';
export const queryClient = new QueryClient();
// required for android
const createChannel = async () => {
const channelId = await notifee.createChannel({
id: 'default',
vibration: true,
name: 'Default Channel',
});
return channelId;
};
// iOS
async function requestUserPermission() {
const settings = await notifee.requestPermission();
if (settings.authorizationStatus >= AuthorizationStatus.AUTHORIZED) {
console.log('Permission settings:', settings);
await createChannel();
} else {
console.log('User declined permissions');
}
}
// foreground
const onMessageHandler = (
remoteMessage: FirebaseMessagingTypes.RemoteMessage,
) => {
const {notification, data} = remoteMessage;
notifee.displayNotification({
title: `<p style="color: #212121; font-size: 15px; font-weight: 500; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;">${notification?.title}</p>`,
body: `<p style="color: #212121; font-size: 13px; font-weight: 400; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;">${notification?.body}</p>`,
android: {
largeIcon:
'https://res.cloudinary.com/omodauda/image/upload/v1667560065/icon_gdhwdi.jpg',
},
data,
});
};
const App = () => {
useEffect(() => {
requestUserPermission();
const unsubMessaging = messaging().onMessage(onMessageHandler);
return () => {
unsubMessaging();
};
}, []);
useEffect(() => {
setTimeout(() => {
SplashScreen.hide();
}, 500);
}, []);
return (
<QueryClientProvider client={queryClient}>
<Provider store={store}>
<PersistGate loading={null} persistor={persistor}>
<MainStack />
<FlashMessage position="top" floating={true} />
</PersistGate>
</Provider>
</QueryClientProvider>
);
};
export default App;