PushNotificationIOS: Use PushNotificationEventName as the key to store in the handler map
Summary: If we are using the same handler for different events, e.g. both `notification` and `localNotification` use `_onNotification()` handler, the former listener stored in `_notifHandlers` would be overridden by the latter so it's impossible to remove the `notification` listener when we call `removeEventListener`. This PR stores the listeners by using `pushNotificationEventName` (notification, localNotification, register or registrationError) as the key. Use the same handler for `notification` and `localNotification`, both listeners will be removed when calling `removeEventListener`. Closes https://github.com/facebook/react-native/pull/10776 Differential Revision: D4168722 Pulled By: hramos fbshipit-source-id: d68581428d2acde314f7b5333feafe1ec7807159
This commit is contained in:
parent
015a497cf1
commit
e51cb349ce
|
@ -258,7 +258,7 @@ class PushNotificationIOS {
|
|||
}
|
||||
);
|
||||
}
|
||||
_notifHandlers.set(handler, listener);
|
||||
_notifHandlers.set(type, listener);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -270,12 +270,12 @@ class PushNotificationIOS {
|
|||
type === 'notification' || type === 'register' || type === 'registrationError' || type === 'localNotification',
|
||||
'PushNotificationIOS only supports `notification`, `register`, `registrationError`, and `localNotification` events'
|
||||
);
|
||||
var listener = _notifHandlers.get(handler);
|
||||
var listener = _notifHandlers.get(type);
|
||||
if (!listener) {
|
||||
return;
|
||||
}
|
||||
listener.remove();
|
||||
_notifHandlers.delete(handler);
|
||||
_notifHandlers.delete(type);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue