-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathApp.js
More file actions
79 lines (68 loc) · 2.23 KB
/
App.js
File metadata and controls
79 lines (68 loc) · 2.23 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
import React, { useEffect } from 'react'
import { View, Button, Alert } from 'react-native';
import notifee from '@notifee/react-native';
import messaging from '@react-native-firebase/messaging';
function App() {
useEffect(() => {
requestPermission();
const unsubscribe = messaging().onMessage(async remoteMessage => {
console.log("remoteMessage",JSON.stringify(remoteMessage))
DisplayNotification(remoteMessage);
// Alert.alert('A new FCM message arrived!', JSON.stringify(remoteMessage));
});
return unsubscribe;
}, []);
const requestPermission = async () => {
const authStatus = await messaging().requestPermission();
}
async function DisplayNotification(remoteMessage) {
// Create a channel
const channelId = await notifee.createChannel({
id: 'default',
name: 'Default Channel',
});
// Display a notification
await notifee.displayNotification({
title: remoteMessage.notification.title,
body: remoteMessage.notification.body,
android: {
channelId,
smallIcon: 'ic_launcher', // optional, defaults to 'ic_launcher'.
},
});
}
async function localDisplayNotification() {
// Create a channel
const channelId = await notifee.createChannel({
id: 'default',
name: 'Default Channel',
});
// Display a notification
notifee.displayNotification({
title: '<p style="color: #4caf50;"><b>Styled HTMLTitle</span></p></b></p> 🙀',
subtitle: '🥳',
body:
'The <p style="text-decoration: line-through">body can</p> also be <p style="color: #ffffff; background-color: #9c27b0"><i>styled too</i></p> 🎉!',
android: {
channelId,
color: '#4caf50',
actions: [
{
title: '<b>Dance</b> 👯',
pressAction: { id: 'dance' },
},
{
title: '<p style="color: #f44336;"><b>Cry</b> 😭</p>',
pressAction: { id: 'cry' },
},
],
},
});
}
return (
<View style={{flex:1,justifyContent:'center',alignItems:'center'}}>
<Button title="Display Notification" onPress={() => localDisplayNotification()} />
</View>
);
}
export default App