-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
feat(app): add support to handle background notification when a native notification activity is visible and react app is dead #5228
feat(app): add support to handle background notification when a native notification activity is visible and react app is dead #5228
Conversation
This pull request is being automatically deployed with Vercel (learn more). 🔍 Inspect: https://vercel.com/invertase/react-native-firebase/F3iv5wfVSCKFviT1KRgpNs87UTza |
Codecov Report
@@ Coverage Diff @@
## master #5228 +/- ##
===========================================
- Coverage 88.86% 36.57% -52.29%
===========================================
Files 109 51 -58
Lines 3743 1518 -2225
Branches 360 360
===========================================
- Hits 3326 555 -2771
- Misses 370 733 +363
- Partials 47 230 +183 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @danwhite-ipc thanks for the PR! This looks good in general - as in, it appears like it would work on API21+ devices and accomplish the task
I left a batch of nitpicks on spacing and wording and such but the only substantive review comment is about the API21 method. Can you have a think on that and adjust as needed?
Then I'll be happy to merge this and get a release out!
packages/app/android/src/reactnative/java/io/invertase/firebase/common/SharedUtils.java
Outdated
Show resolved
Hide resolved
packages/app/android/src/reactnative/java/io/invertase/firebase/common/SharedUtils.java
Outdated
Show resolved
Hide resolved
packages/app/android/src/reactnative/java/io/invertase/firebase/common/SharedUtils.java
Outdated
Show resolved
Hide resolved
packages/app/android/src/reactnative/java/io/invertase/firebase/common/SharedUtils.java
Outdated
Show resolved
Hide resolved
...s/app/android/src/reactnative/java/io/invertase/firebase/common/ReactNativeFirebaseJSON.java
Outdated
Show resolved
Hide resolved
ArrayList<String> backgroundActivities = json.getArrayValue("background_activity_names"); | ||
|
||
if(backgroundActivities.size() != 0) { | ||
List<ActivityManager.AppTask> taskInfo = activityManager.getAppTasks(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an API21 call and we are still minSdkVersion 16 https://developer.android.com/reference/android/app/ActivityManager#getAppTasks()
Is there a way to accomplish this using APIs available on 16? If not it's safe to say the audience for API<21 is vanishingly small (RN0.64 bumps minSdkVersion to 21) so I'd accept an SDK version check to gate the API usage and make it safe, and then you would likely need to put a "NewApi" suppression in there to pass the lint check I just installed to guard against this #5208 after one slipped through recently
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have added support for API<21
…e/common/SharedUtils.java Co-authored-by: Mike Hardy <[email protected]>
…e/common/SharedUtils.java Co-authored-by: Mike Hardy <[email protected]>
…e/common/SharedUtils.java Co-authored-by: Mike Hardy <[email protected]>
…e/common/SharedUtils.java Co-authored-by: Mike Hardy <[email protected]>
Co-authored-by: Mike Hardy <[email protected]>
Co-authored-by: Mike Hardy <[email protected]>
…e/common/ReactNativeFirebaseJSON.java Co-authored-by: Mike Hardy <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@danwhite-ipc This looks great, thank you for handling the old API!
I had a few trivial nitpicks with exception of an important suggestion on the Activity name comparison to make it work better (I think)
If everything looks good to you, accept those and once CI passes I should be able to release this - I have a release preparing right now
packages/app/android/src/reactnative/java/io/invertase/firebase/common/SharedUtils.java
Outdated
Show resolved
Hide resolved
packages/app/android/src/reactnative/java/io/invertase/firebase/common/SharedUtils.java
Outdated
Show resolved
Hide resolved
} | ||
} | ||
|
||
if (currentActivity != "" && backgroundActivities.contains(currentActivity)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤔 two issues here -
1- using !=
on java strings asks if they are the exact same in-memory location, not if the strings are equal, you have to use String.equals()
for string equality. In Javascript even it should be !==
vs !=
.
2- NullPointerExceptions on string comparison are a classic Java issue, so if you use Java String.equals()
the safe way (to protect against nulls) is to reverse them and use the known-good string first, e.g. !"".equals(currentActivity)
if (currentActivity != "" && backgroundActivities.contains(currentActivity)) { | |
if (!"".equals(currentActivity) && backgroundActivities.contains(currentActivity)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Happy with the suggestion but it looks like your missing a )
at the end of your equals(currentActivity)
check
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤦 yes indeed. The perils of coding in a web text box - good spot - updated - hopefully better?
…e/common/SharedUtils.java Co-authored-by: Mike Hardy <[email protected]>
…e/common/SharedUtils.java Co-authored-by: Mike Hardy <[email protected]>
Co-authored-by: Mike Hardy <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
only rejecting so I can commit the suggestion / then approve / then merge
as mentioned I'm preparing a release literally this hour so I'm just trying to hustle it up
packages/app/android/src/reactnative/java/io/invertase/firebase/common/SharedUtils.java
Outdated
Show resolved
Hide resolved
Really strange! Sorry this is likely generating notification spam for you, but I really wanted to be able to commit the change. GitHub normally offers me that button as an option but it did not this time. At any rate, if you submit a correct version of that string compare this can go out the door this afternoon... |
…e/common/SharedUtils.java Co-authored-by: Mike Hardy <[email protected]>
Sorry I signed off for the night so only just seen your message and jumped back on. I committed your update and hopefully all is fine now. |
Ah no worries - still prime time for me ;-). I pulled your fork as a remote locally and fixed one small thing, I'll shepherd it to merge + release today. This is a cool feature, I'm excited to see it go live - thanks for contributing it! |
Superceded by #5235 |
@mikehardy No worries, always good to contribute |
Release 11.4.1 just went out with the change related to this among other fixes + features. Enjoy! 🚀 |
Description
Allow for configuration of background native activities.
Related issues
Fixes #5219
Release Summary
Allow for configuration of background native activities to allow for the handling of background messages when a native activity is visible and the react native app is dead.
Checklist
Android
iOS
e2e
tests added or updated inpackages/\*\*/e2e
jest
tests added or updated inpackages/\*\*/__tests__
Test Plan
Think
react-native-firebase
is great? Please consider supporting the project with any of the below:React Native Firebase
andInvertase
on Twitter