-
Notifications
You must be signed in to change notification settings - Fork 378
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug]: Problem with addEventListener removeEventListener #1610
Comments
Are you using some libraries to navigate? Because for example |
Did you find a solution to this? I'm using a combination of // route.tsx
useFocusEffect(
useCallback(() => {
addForegroundWillDisplayListener();
return () => {
removeForegroundWillDisplayListener();
};
}, []),
);
// PushNotificationsProvider.tsx
const onForegroundWillDisplay = (event: NotificationWillDisplayEvent) => {
event.preventDefault();
};
function addForegroundWillDisplayListener() {
removeForegroundWillDisplayListener();
OneSignal.Notifications.addEventListener(
'foregroundWillDisplay',
onForegroundWillDisplay,
);
}
function removeForegroundWillDisplayListener() {
OneSignal.Notifications.removeEventListener(
'foregroundWillDisplay',
onForegroundWillDisplay,
);
} |
The problem is still here, event is removed but notifications don't show up again |
Same here |
Hello guys, I'm having similar issues. After I register a I don't know if it is happening on Android side. I'm working with iOS-only for now. Let's take a look at my workaround:
Currently, on
As you guys noted, we may have a flag, or something, that is not being unset. After we call Apparently, after we call I didn't have time to deep dive into it. The cache seems to be using the We can see that if there's an event registered, the Well, hope I can help someone else. This workaround is working for me, even tho its ugly and not the ideal :/ |
Any updates on this? |
Still happening |
This is still an issue. I can't get my listener to properly be removed either so its basically stacking listeners on each re-render |
Still reproducing this error with "react-native-onesignal": "^5.2.6" Update: This is not reproduced in production builds. The reference to the listener is cleared properly when closing the app. Reload does not clean up this properly and new instances of listener function are not cleared since they have a different address in memory. |
It seems that the issue is cause by missing ios implementation for addNotificationClickListener and addNotificationForegroundLifecycleListener on lines 319 and 326 in file: I tested the same behaviour with addPermissionObserver and removePermissionObserver. I could reload the app many time and the event callback was triggered only once. |
Hi everyone, I apologize for not getting eyes on this sooner. Thank you for the details. We will start by reproducing this behavior. |
What happened?
It seems that removeEventListener doesn't work as expected
I have the following code :
So when I'm on my page and I receive a notification my console says "Event listener called". When I leave the page I remove the event listener (with the return method of the useEffect) then when I receive a notification my console don't say "Event listener called". So... It's working ! But... no, because the notification is not shown. So in my opinion it seems that the removeEventListener does his work properly, but that the preventDefault() is still working because no notification with refresh_messages to true are displayed.
Steps to reproduce?
What did you expect to happen?
As I removed the listener. Then every notification should display
React Native OneSignal SDK version
5.0.3
Which platform(s) are affected?
Relevant log output
No response
Code of Conduct
The text was updated successfully, but these errors were encountered: