Skip to content
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

Closed
wants to merge 14 commits into from

Conversation

danwhite-ipc
Copy link
Contributor

@danwhite-ipc danwhite-ipc commented Apr 28, 2021

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

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
    • Yes
  • My change supports the following platforms;
    • Android
    • iOS
  • My change includes tests;
    • e2e tests added or updated in packages/\*\*/e2e
    • jest tests added or updated in packages/\*\*/__tests__
  • I have updated TypeScript types that are affected by my change.
  • This is a breaking change;
    • Yes
    • No

Test Plan


Think react-native-firebase is great? Please consider supporting the project with any of the below:

@vercel
Copy link

vercel bot commented Apr 28, 2021

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/invertase/react-native-firebase/F3iv5wfVSCKFviT1KRgpNs87UTza
✅ Preview: https://react-native-f-git-fork-ipcortex-feature-backgroundactiv-f67c10.vercel.app

@CLAassistant
Copy link

CLAassistant commented Apr 28, 2021

CLA assistant check
All committers have signed the CLA.

@codecov
Copy link

codecov bot commented Apr 28, 2021

Codecov Report

Merging #5228 (9f5c3bf) into master (574f691) will decrease coverage by 52.30%.
The diff coverage is n/a.

❗ Current head 9f5c3bf differs from pull request most recent head 6a2cf5d. Consider uploading reports for the commit 6a2cf5d to get more accurate results

@@             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     

Copy link
Collaborator

@mikehardy mikehardy left a 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/firebase-schema.json Outdated Show resolved Hide resolved
packages/app/firebase-schema.json Outdated Show resolved Hide resolved
ArrayList<String> backgroundActivities = json.getArrayValue("background_activity_names");

if(backgroundActivities.size() != 0) {
List<ActivityManager.AppTask> taskInfo = activityManager.getAppTasks();
Copy link
Collaborator

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

Copy link
Contributor Author

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

@mikehardy mikehardy added the Workflow: Needs Review Pending feedback or review from a maintainer. label Apr 28, 2021
@mikehardy mikehardy added Workflow: Waiting for User Response Blocked waiting for user response. and removed Workflow: Needs Review Pending feedback or review from a maintainer. labels Apr 28, 2021
@danwhite-ipc danwhite-ipc changed the title Feat(app): add support to handle background notification when a native notification activity is visible and react app is dead feat(app): add support to handle background notification when a native notification activity is visible and react app is dead Apr 29, 2021
@danwhite-ipc danwhite-ipc requested a review from mikehardy April 29, 2021 09:31
Copy link
Collaborator

@mikehardy mikehardy left a 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

}
}

if (currentActivity != "" && backgroundActivities.contains(currentActivity)) {
Copy link
Collaborator

@mikehardy mikehardy Apr 29, 2021

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)

Suggested change
if (currentActivity != "" && backgroundActivities.contains(currentActivity)) {
if (!"".equals(currentActivity) && backgroundActivities.contains(currentActivity)) {

Copy link
Contributor Author

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

Copy link
Collaborator

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?

packages/app/firebase-schema.json Outdated Show resolved Hide resolved
@mikehardy mikehardy added the Workflow: Pending Merge Waiting on CI or similar label Apr 29, 2021
Copy link
Collaborator

@mikehardy mikehardy left a 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

@mikehardy
Copy link
Collaborator

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...

@danwhite-ipc
Copy link
Contributor Author

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.

@mikehardy
Copy link
Collaborator

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!

@mikehardy
Copy link
Collaborator

Superceded by #5235

@mikehardy mikehardy closed this Apr 29, 2021
@mikehardy mikehardy removed Workflow: Pending Merge Waiting on CI or similar Workflow: Waiting for User Response Blocked waiting for user response. labels Apr 29, 2021
@danwhite-ipc
Copy link
Contributor Author

@mikehardy No worries, always good to contribute

@mikehardy
Copy link
Collaborator

Release 11.4.1 just went out with the change related to this among other fixes + features. Enjoy! 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

setBackgroundMessageHandler not working with multiple native Activities
3 participants