-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHome.js
76 lines (68 loc) · 2.17 KB
/
Home.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
import React, {Component} from 'react';
import {View, Button} from 'react-native';
import {Notifications} from 'react-native-notifications';
const scheduleNotification = (title, body, id, index) => {
const date = new Date(Date.now() + 20 * (index + 1) * 1000);
console.log(date);
const notification = {
title,
body,
silent: false,
userInfo: {},
fireDate: date,
};
Notifications.postLocalNotification(notification, id);
};
class Home extends Component {
constructor(props) {
super(props);
Notifications.registerRemoteNotifications();
Notifications.events().registerNotificationReceivedForeground(
(
notification: Notification,
completion: (response: NotificationCompletion) => void,
) => {
console.log('Notification Received - Foreground', notification.payload);
Notifications.postLocalNotification({
title: notification.payload['gcm.notification.title'],
body: notification.payload['gcm.notification.body'],
});
// Calling completion on iOS with `alert: true` will present the native iOS inApp notification.
completion({alert: true, sound: true, badge: false});
},
);
Notifications.events().registerNotificationOpened(
(notification: Notification, completion) => {
console.log(`Notification opened: ${notification.payload}`);
completion();
},
);
}
render() {
return (
<View style={{justifyContent: 'center'}}>
<Button
title="Send Local notification"
onPress={() =>
Notifications.postLocalNotification({
title: 'Local notification',
body: 'This notification was generated by the app!',
extra: 'data',
})
}></Button>
{/* <Button
style={{marginVertical: 10}}
title="Send Local notification in 1 min"
onPress={() =>
scheduleNotification(
'Local notification in 1 min',
'This notification was generated by the app!',
11231,
6,
)
}></Button> */}
</View>
);
}
}
export default Home;