2
0
mirror of synced 2025-02-18 17:28:24 +00:00

[notifications] Rename onPressed to onOpened

This commit is contained in:
Chris Bianca 2018-02-24 11:32:14 +00:00
parent 07bc258c08
commit ee3b2932ef
5 changed files with 77 additions and 84 deletions

View File

@ -40,7 +40,7 @@ static NSString *const MESSAGING_NOTIFICATION_RECEIVED = @"messaging_notificatio
// Notifications
static NSString *const NOTIFICATIONS_NOTIFICATION_DISPLAYED = @"notifications_notification_displayed";
static NSString *const NOTIFICATIONS_NOTIFICATION_PRESSED = @"notifications_notification_pressed";
static NSString *const NOTIFICATIONS_NOTIFICATION_OPENED = @"notifications_notification_opened";
static NSString *const NOTIFICATIONS_NOTIFICATION_RECEIVED = @"notifications_notification_received";
// AdMob

View File

@ -75,18 +75,15 @@ RCT_EXPORT_MODULE();
if ([self isIOS89]) {
NSString *event;
if (RCTSharedApplication().applicationState == UIApplicationStateBackground) {
// notification_displayed
event = NOTIFICATIONS_NOTIFICATION_DISPLAYED;
} else if (RCTSharedApplication().applicationState == UIApplicationStateInactive) {
// notification_displayed
event = NOTIFICATIONS_NOTIFICATION_PRESSED;
event = NOTIFICATIONS_NOTIFICATION_OPENED;
} else {
// notification_received
event = NOTIFICATIONS_NOTIFICATION_RECEIVED;
}
NSDictionary *notification = [self parseUILocalNotification:localNotification];
if (event == NOTIFICATIONS_NOTIFICATION_PRESSED) {
if (event == NOTIFICATIONS_NOTIFICATION_OPENED) {
notification = @{
@"action": UNNotificationDefaultActionIdentifier,
@"notification": notification
@ -108,14 +105,11 @@ RCT_EXPORT_MODULE();
NSString *event;
if (RCTSharedApplication().applicationState == UIApplicationStateBackground) {
// notification_displayed
event = NOTIFICATIONS_NOTIFICATION_DISPLAYED;
} else if ([self isIOS89]) {
if (RCTSharedApplication().applicationState == UIApplicationStateInactive) {
// notification_displayed
event = NOTIFICATIONS_NOTIFICATION_PRESSED;
event = NOTIFICATIONS_NOTIFICATION_OPENED;
} else {
// notification_received
event = NOTIFICATIONS_NOTIFICATION_RECEIVED;
}
} else {
@ -127,8 +121,8 @@ RCT_EXPORT_MODULE();
}
NSDictionary *notification = [self parseUserInfo:userInfo];
// For onPressed events, we set the default action name as iOS 8/9 has no concept of actions
if (event == NOTIFICATIONS_NOTIFICATION_PRESSED) {
// For onOpened events, we set the default action name as iOS 8/9 has no concept of actions
if (event == NOTIFICATIONS_NOTIFICATION_OPENED) {
notification = @{
@"action": UNNotificationDefaultActionIdentifier,
@"notification": notification
@ -198,7 +192,7 @@ didReceiveNotificationResponse:(UNNotificationResponse *)response
#endif
NSDictionary *message = [self parseUNNotificationResponse:response];
[self sendJSEvent:self name:NOTIFICATIONS_NOTIFICATION_PRESSED body:message];
[self sendJSEvent:self name:NOTIFICATIONS_NOTIFICATION_OPENED body:message];
completionHandler();
}
@ -374,7 +368,7 @@ RCT_EXPORT_METHOD(setBadge: (NSInteger) number) {
if (emitter.bridge) {
[RNFirebaseUtil sendJSEvent:emitter name:name body:body];
} else {
if ([name isEqualToString:NOTIFICATIONS_NOTIFICATION_PRESSED] && !initialNotification) {
if ([name isEqualToString:NOTIFICATIONS_NOTIFICATION_OPENED] && !initialNotification) {
initialNotification = body;
}
// PRE-BRIDGE-EVENTS: Consider enabling this to allow events built up before the bridge is built to be sent to the JS side
@ -698,7 +692,7 @@ RCT_EXPORT_METHOD(setBadge: (NSInteger) number) {
}
- (NSArray<NSString *> *)supportedEvents {
return @[NOTIFICATIONS_NOTIFICATION_DISPLAYED, NOTIFICATIONS_NOTIFICATION_PRESSED, NOTIFICATIONS_NOTIFICATION_RECEIVED];
return @[NOTIFICATIONS_NOTIFICATION_DISPLAYED, NOTIFICATIONS_NOTIFICATION_OPENED, NOTIFICATIONS_NOTIFICATION_RECEIVED];
}
+ (BOOL)requiresMainQueueSetup
@ -712,4 +706,3 @@ RCT_EXPORT_METHOD(setBadge: (NSInteger) number) {
@implementation RNFirebaseNotifications
@end
#endif

View File

@ -9,7 +9,7 @@ import { generatePushID, isObject } from '../../utils';
import type { NativeNotification } from './types';
export type NotificationPressed = {
export type NotificationOpened = {
action: string,
notification: Notification,
};

View File

@ -18,10 +18,10 @@ import {
} from './types';
import type App from '../core/app';
import type { NotificationPressed } from './Notification';
import type { NotificationOpened } from './Notification';
import type {
NativeNotification,
NativeNotificationPressed,
NativeNotificationOpened,
Schedule,
} from './types';
@ -31,15 +31,15 @@ type OnNotificationObserver = {
next: OnNotification,
};
type OnNotificationPressed = NotificationPressed => any;
type OnNotificationOpened = NotificationOpened => any;
type OnNotificationPressedObserver = {
next: OnNotificationPressed,
type OnNotificationOpenedObserver = {
next: OnNotificationOpened,
};
const NATIVE_EVENTS = [
'notifications_notification_displayed',
'notifications_notification_pressed',
'notifications_notification_opened',
'notifications_notification_received',
];
@ -86,12 +86,12 @@ export default class Notifications extends ModuleBase {
SharedEventEmitter.addListener(
// sub to internal native event - this fans out to
// public event name: onNotificationPressed
'notifications_notification_pressed',
(notificationPressed: NativeNotificationPressed) => {
SharedEventEmitter.emit('onNotificationPressed', {
action: notificationPressed.action,
notification: new Notification(notificationPressed.notification),
// public event name: onNotificationOpened
'notifications_notification_opened',
(notificationOpened: NativeNotificationOpened) => {
SharedEventEmitter.emit('OnNotificationOpened', {
action: notificationOpened.action,
notification: new Notification(notificationOpened.notification),
});
}
);
@ -111,22 +111,22 @@ export default class Notifications extends ModuleBase {
/**
* Cancel all notifications
* @returns {*}
*/
cancelAllNotifications(): Promise<void> {
return getNativeModule(this).cancelAllNotifications();
cancelAllNotifications(): void {
getNativeModule(this).cancelAllNotifications();
}
/**
* Cancel a notification by id.
* @param id
* @returns {*}
* @param notificationId
*/
cancelNotification(notificationId: string): Promise<void> {
cancelNotification(notificationId: string): void {
if (!notificationId) {
return Promise.reject(new Error('Missing notificationId'));
throw new Error(
'Notifications: cancelNotification expects a `notificationId`'
);
}
return getNativeModule(this).cancelNotification(notificationId);
getNativeModule(this).cancelNotification(notificationId);
}
/**
@ -207,8 +207,8 @@ export default class Notifications extends ModuleBase {
};
}
onNotificationPressed(
nextOrObserver: OnNotificationPressed | OnNotificationPressedObserver
onNotificationOpened(
nextOrObserver: OnNotificationOpened | OnNotificationOpenedObserver
): () => any {
let listener;
if (isFunction(nextOrObserver)) {
@ -217,37 +217,37 @@ export default class Notifications extends ModuleBase {
listener = nextOrObserver.next;
} else {
throw new Error(
'Notifications.onNotificationPressed failed: First argument must be a function or observer object with a `next` function.'
'Notifications.onNotificationOpened failed: First argument must be a function or observer object with a `next` function.'
);
}
getLogger(this).info('Creating onNotificationPressed listener');
SharedEventEmitter.addListener('onNotificationPressed', listener);
getLogger(this).info('Creating onNotificationOpened listener');
SharedEventEmitter.addListener('onNotificationOpened', listener);
return () => {
getLogger(this).info('Removing onNotificationPressed listener');
SharedEventEmitter.removeListener('onNotificationPressed', listener);
getLogger(this).info('Removing onNotificationOpened listener');
SharedEventEmitter.removeListener('onNotificationOpened', listener);
};
}
/**
* Remove all delivered notifications.
* @returns {*}
*/
removeAllDeliveredNotifications(): Promise<void> {
return getNativeModule(this).removeAllDeliveredNotifications();
removeAllDeliveredNotifications(): void {
getNativeModule(this).removeAllDeliveredNotifications();
}
/**
* Remove a delivered notification.
* @param notificationId
* @returns {*}
*/
removeDeliveredNotification(notificationId: string): Promise<void> {
removeDeliveredNotification(notificationId: string): void {
if (!notificationId) {
return Promise.reject(new Error('Missing notificationId'));
throw new Error(
'Notifications: removeDeliveredNotification expects a `notificationId`'
);
}
return getNativeModule(this).removeDeliveredNotification(notificationId);
getNativeModule(this).removeDeliveredNotification(notificationId);
}
/**

View File

@ -161,7 +161,7 @@ export type NativeNotification = {|
title: string,
|};
export type NativeNotificationPressed = {|
export type NativeNotificationOpened = {|
action: string,
notification: NativeNotification,
|};