-
Notifications
You must be signed in to change notification settings - Fork 24.4k
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
Allow listen to foreground or background notification separately #1524
Conversation
4699811
to
a4c7b41
Compare
@brentvatne I rebased this and made the test pass. Would you mind help me review this or assign a reviewer for this? |
Hi @lazywei! Some thoughts:
I don't have a lot of experience with this area so I'm curious what other smarter people like @ide think. |
Probably makes more sense to put this logic in your app's JS -- when your JS gets the "notification" event, check whether the application is foregrounded or not. I would also be surprised if this diff works... React Native does not work with backgrounded apps right now, and I think you need a different app delegate method to handle notifications while backgrounded. |
I agree with you. However, the thing is currently we don't have a proper way to check the app's foreground/background state (at least I'm not aware of).
Actually it works pretty well in my project (I'm using this PR in my app). It doesn't require RN work with backgrounded app I think. It's totally native solution -- only it emits different event for background / foreground app. |
oh, that's cool. Thanks. |
Thanks for it anyways @lazywei, even if it didn't work out 😄 |
In many cases, the app need to respond to the notification in different ways.
Take chat app as an instance. The app need to jump to the certain chatroom when users opens the notification from background, while it shouldn't jump to anywhere when the chat app is in foreground.
So I split the notification type to foreground and background. In this way, the developers can listen to different type of notification accordingly.
Usage: