forked from holmesal/react-native-ios-notification-actions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ios.js
59 lines (49 loc) · 1.63 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
55
56
57
58
59
import {NativeModules, NativeAppEventEmitter} from 'react-native';
const {RNNotificationActions} = NativeModules;
let actions = {};
todoComplete = () => {
console.info('TODO - implement complete callbacks for objective-c (the callback was already called in this case)');
};
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) {
console.info('got action interaction!', body);
onComplete(body.source, todoComplete, body.text);
}
});
}
}
export class Category {
constructor(opts) {
// TODO - check options
this.opts = opts;
}
}
export const updateCategories = (categories) => {
console.info('updating categories!', categories);
console.info(RNNotificationActions);
//RNNotificationActions.logTest('heyooO!');
let cats = categories.map((cat) => {
return Object.assign({}, cat.opts, {
actions: cat.opts.actions.map((action) => action.opts)
})
});
console.info('updating categories', cats);
RNNotificationActions.updateCategories(cats);
// Re-update when permissions change
NativeAppEventEmitter.addListener('remoteNotificationsRegistered', () => {
console.info('updating notification categories in response to permission change');
RNNotificationActions.updateCategories(cats);
});
};
export default {
Action,
Category,
updateCategories
};