-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNotifications.js
112 lines (98 loc) · 3.4 KB
/
Notifications.js
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
import React, { Component } from 'react';
import { View, Button } from 'react-native';
import notifee, { EventType, TimestampTrigger, TriggerType } from '@notifee/react-native'
export default class template extends Component {
constructor(props) {
super(props)
this.onDisplayNotification = this.onDisplayNotification.bind(this)
this.updateNotification = this.updateNotification.bind(this)
this.state = {
channelId: {}
}
}
componentDidMount() {
this.createNotificationListeners()
}
createNotificationListeners() {
this.unsubscribe = notifee.onForegroundEvent(({ type, detail }) => {
if (type === EventType.ACTION_PRESS && detail.pressAction.id) {
console.log('User pressed an action with the id: ', detail.pressAction.id);
}
switch (type) {
case EventType.DISMISSED:
console.log('User dismissed notification', detail.notification);
break
case EventType.PRESS:
console.log('User pressed notification', detail.notification);
break
}
})
}
async onDisplayNotification() {
// // Create a channel
// const channelId = await notifee.createChannel({
// id: 'default',
// name: 'Default Channel',
// })
// // Display a notification
// await notifee.displayNotification({
// title: 'New message',
// body: 'You have a new message from Sarah!',
// android: {
// channelId: 'messages',
// actions: [
// {
// title: 'Reply',
// icon: 'https://my-cdn.com/icons/reply.png',
// pressAction: {
// id: 'reply',
// },
// input: true, // enable free text input
// },
// ],
// },
// })
const date = new Date(Date.now());
date.setHours(20);
date.setMinutes(39);
// Create a time-based trigger
const trigger: TimestampTrigger = {
type: TriggerType.TIMESTAMP,
timestamp: date.getTime(), // fire at 11:10am (10 minutes before meeting)
};
// Create a trigger notification
await notifee.createTriggerNotification(
{
title: 'Meeting with Jane',
body: 'Today at 11:20am',
android: {
channelId: 'your-channel-id',
},
},
trigger,
);
}
async updateNotification() {
// Sometime later...
const channelId = await notifee.createChannel({
id: 'default',
name: 'Default Channel',
})
await notifee.displayNotification({
id: '123',
title: 'Updated Notification Title',
body: 'Updated main body content of the notification',
android: {
channelId,
},
})
}
render() {
return (
<View style={{ flex: 1, justifyContent: 'space-evenly' }}>
<Button title="Display Notification" onPress={this.onDisplayNotification} />
<Button title="Update Notification" onPress={this.updateNotification} />
</View>
)
}
}