forked from holmesal/react-native-ios-notification-actions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ios.js
54 lines (43 loc) · 1.25 KB
/
index.ios.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
import { NativeModules, NativeAppEventEmitter } from 'react-native';
const { RNNotificationActions } = NativeModules;
let actions = {};
function handleActionCompleted() {
RNNotificationActions.callCompletionHandler();
};
export class Action {
constructor(opts, onComplete) {
// TODO - check options
this.opts = opts;
this.onComplete = onComplete;
// When a notification is received, we'll call this action by it's identifier
actions[opts.identifier] = this;
NativeAppEventEmitter.addListener('notificationActionReceived', (body) => {
if (body.identifier === opts.identifier) {
onComplete(body, handleActionCompleted);
}
});
}
}
export class Category {
constructor(opts) {
// TODO - check options
this.opts = opts;
}
}
export const updateCategories = (categories) => {
let cats = categories.map((cat) => {
return Object.assign({}, cat.opts, {
actions: cat.opts.actions.map((action) => action.opts)
});
});
RNNotificationActions.updateCategories(cats);
// Re-update when permissions change
NativeAppEventEmitter.addListener('remoteNotificationsRegistered', () => {
RNNotificationActions.updateCategories(cats);
});
};
export default {
Action,
Category,
updateCategories
};