Skip to content

Commit e51cb34

Browse files
ianlinFacebook Github Bot
authored andcommitted
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 #10776 Differential Revision: D4168722 Pulled By: hramos fbshipit-source-id: d68581428d2acde314f7b5333feafe1ec7807159
1 parent 015a497 commit e51cb34

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

Libraries/PushNotificationIOS/PushNotificationIOS.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ class PushNotificationIOS {
258258
}
259259
);
260260
}
261-
_notifHandlers.set(handler, listener);
261+
_notifHandlers.set(type, listener);
262262
}
263263

264264
/**
@@ -270,12 +270,12 @@ class PushNotificationIOS {
270270
type === 'notification' || type === 'register' || type === 'registrationError' || type === 'localNotification',
271271
'PushNotificationIOS only supports `notification`, `register`, `registrationError`, and `localNotification` events'
272272
);
273-
var listener = _notifHandlers.get(handler);
273+
var listener = _notifHandlers.get(type);
274274
if (!listener) {
275275
return;
276276
}
277277
listener.remove();
278-
_notifHandlers.delete(handler);
278+
_notifHandlers.delete(type);
279279
}
280280

281281
/**

0 commit comments

Comments
 (0)