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(ios, messaging): Allow notifications in foreground on iOS, configure in firebase.json #6407

Merged

Conversation

ken0nek
Copy link
Contributor

@ken0nek ken0nek commented Jul 18, 2022

Description

Resolve this TODO comment ("in a later version allow customising completion options in JS code").

Added a key to configure UNNotificationPresentationOptions

Related issues

Release Summary

Can configure UNNotificationPresentationOptions on iOS via firebase.json

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 Jul 18, 2022

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated
react-native-firebase ✅ Ready (Inspect) Visit Preview Jul 19, 2022 at 4:35AM (UTC)
1 Ignored Deployment
Name Status Preview Updated
react-native-firebase-next ⬜️ Ignored (Inspect) Jul 19, 2022 at 4:35AM (UTC)

@ken0nek ken0nek changed the title Work/un notification presentation option config Configure foreground presentation options on iOS via firebase.json Jul 18, 2022
@ken0nek ken0nek changed the title Configure foreground presentation options on iOS via firebase.json fix(ios, messaging): Configure foreground presentation options on iOS via firebase.json Jul 18, 2022
Comment on lines +106 to +128
// if list or banner is true, ignore `alert` property
if (banner || list) {
if (banner) {
if (@available(iOS 14, *)) {
presentationOptions |= UNNotificationPresentationOptionBanner;
} else {
// for iOS 13 we need to set `alert`
presentationOptions |= UNNotificationPresentationOptionAlert;
}
}

if (list) {
if (@available(iOS 14, *)) {
presentationOptions |= UNNotificationPresentationOptionList;
} else {
// for iOS 13 we need to set `alert`
presentationOptions |= UNNotificationPresentationOptionAlert;
}
}
} else if (alert) {
// TODO: Remove `alert` once iOS 14 becomes the minimum deployment target
presentationOptions |= UNNotificationPresentationOptionAlert;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same logic in notifee

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes - I was silently reading those as they went through, so I followed things as they went to the final solution, this looks good to me

@mikehardy mikehardy changed the title fix(ios, messaging): Configure foreground presentation options on iOS via firebase.json feat(ios, messaging): Allow notifications in foreground on iOS, configure in firebase.json Jul 19, 2022
mikehardy
mikehardy previously approved these changes Jul 19, 2022
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.

Looks good to me, thanks a lot for this! Normally I tell people to use Notifee for device-local-anything when it comes to notification presentation but including at least a minimum for foreground (similar to background) is very nice.

One quick question: is there a feature gap on the android side as well for notifications showing up in the default state?

Comment on lines +106 to +128
// if list or banner is true, ignore `alert` property
if (banner || list) {
if (banner) {
if (@available(iOS 14, *)) {
presentationOptions |= UNNotificationPresentationOptionBanner;
} else {
// for iOS 13 we need to set `alert`
presentationOptions |= UNNotificationPresentationOptionAlert;
}
}

if (list) {
if (@available(iOS 14, *)) {
presentationOptions |= UNNotificationPresentationOptionList;
} else {
// for iOS 13 we need to set `alert`
presentationOptions |= UNNotificationPresentationOptionAlert;
}
}
} else if (alert) {
// TODO: Remove `alert` once iOS 14 becomes the minimum deployment target
presentationOptions |= UNNotificationPresentationOptionAlert;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes - I was silently reading those as they went through, so I followed things as they went to the final solution, this looks good to me

@mikehardy mikehardy added Workflow: Waiting for User Response Blocked waiting for user response. Workflow: Pending Merge Waiting on CI or similar labels Jul 19, 2022
@codecov
Copy link

codecov bot commented Jul 19, 2022

Codecov Report

Merging #6407 (01fe662) into main (254f9fc) will decrease coverage by 46.48%.
The diff coverage is n/a.

❗ Current head 01fe662 differs from pull request most recent head 027192c. Consider uploading reports for the commit 027192c to get more accurate results

@@             Coverage Diff             @@
##             main    #6407       +/-   ##
===========================================
- Coverage   72.31%   25.84%   -46.47%     
===========================================
  Files         109       97       -12     
  Lines        4655     4289      -366     
  Branches     1048     1048               
===========================================
- Hits         3366     1108     -2258     
- Misses       1211     2581     +1370     
- Partials       78      600      +522     

@ken0nek
Copy link
Contributor Author

ken0nek commented Jul 19, 2022

One quick question: is there a feature gap on the android side as well for notifications showing up in the default state?

I suppose no.

As you can see this doc, foreground presentation options for Remote Notification is only for iOS.

@ken0nek
Copy link
Contributor Author

ken0nek commented Jul 19, 2022

Hmm, I got no diff even after executing yarn lint:markdown 🤔

@mikehardy
Copy link
Collaborator

I suppose no.

As you can see this doc, foreground presentation options for Remote Notification is only for iOS.

Hmm - I think of Notifee as going "higher" in the stack, we are below them (in my mental model - that is, lower level) and firebase-android-sdk would be even lower than that, with the GCM libraries and FCM receipt on the device as the bottom / most inner part.

My question was aimed at: as GCM/FCM hits the device and firebase-android-sdk executes things / potentially booting the app and loading the Java code then the javascript bundle (similar to firebase-ios-sdk loading the objective-c code in @react-native-firebase/messaging that you changed) - if the app is in the foreground is a notification actually posted ever? Should it be possible in the way you added this feature here?

I have not actually tested this (at least not recently enough to remember) so I'm unsure - I was mostly curious for the results of any testing if you've done it. I'm okay with just doing an iOS feature and waiting for someone interested (or myself) to do same for android if there's a feature gap, I was just curious if you knew since I assume you're testing this with a react-native app so you looked at iOS and could probably check android with same codebase / testing setup

@mikehardy
Copy link
Collaborator

Hmm, I got no diff even after executing yarn lint:markdown thinking

I see this:


mike@bistromath:~/work/Invertase/react-native-firebase (work/UNNotificationPresentationOption-config) % yarn lint:markdown -w
yarn run v1.22.18
$ prettier --check "docs/**/*.md" -w
Checking formatting...
[warn] docs/messaging/usage/index.md
[warn] Code style issues fixed in the above file.
Done in 3.44s.
mike@bistromath:~/work/Invertase/react-native-firebase (work/UNNotificationPresentationOption-config *) % git diff
diff --git a/docs/messaging/usage/index.md b/docs/messaging/usage/index.md
index a93f73e67..1383dd45a 100644
--- a/docs/messaging/usage/index.md
+++ b/docs/messaging/usage/index.md
@@ -395,13 +395,7 @@ Refer to [UNNotificationPresentationOptions](https://developer.apple.com/documen
 // <projectRoot>/firebase.json
 {
   "react-native": {
-    "messaging_ios_foreground_presentation_options": [
-      "badge",
-      "sound",
-      "alert",
-      "list",
-      "banner"
-    ]
+    "messaging_ios_foreground_presentation_options": ["badge", "sound", "alert", "list", "banner"]
   }
 }

@mikehardy
Copy link
Collaborator

(I pushed a commit with that diff to your branch as an attempt at higher velocity - hopefully no offense is taken! :-) )

@ken0nek
Copy link
Contributor Author

ken0nek commented Jul 19, 2022

Thank you for updating the doc!

I was mostly curious for the results of any testing if you've done it.
I was just curious if you knew since I assume you're testing this with a react-native app so you looked at iOS

I tested this feature by patching @react-native-firebase/messaging and @react-native-firebase/app in my company codebase. It works on iOS by sending a remote push notification, plus I got a notification on Android too.

I'm okay with just doing an iOS feature and waiting for someone interested (or myself) to do same for android if there's a feature gap

Maybe we can explore the code around onMessageReceived on Android in the future?

.spellcheck.dict.txt Show resolved Hide resolved
.spellcheck.dict.txt Show resolved Hide resolved
mikehardy
mikehardy previously approved these changes Jul 19, 2022
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.

looks even better now, thanks for organizing + patching up the spellcheck dictionary

@mikehardy
Copy link
Collaborator

🤔 perhaps this collided with #6406 and this needs a rebase against current main ?

@ken0nek ken0nek force-pushed the work/UNNotificationPresentationOption-config branch from def4def to 027192c Compare July 19, 2022 04:29
@ken0nek
Copy link
Contributor Author

ken0nek commented Jul 19, 2022

🤔 perhaps this collided with #6406 and this needs a rebase against current main ?

Rebased using the latest main 👍

@mikehardy
Copy link
Collaborator

I'll be shocked if this doesn't do it - I'm about to be done for the night so won't see the result for hours but I imagine it will be either all green or perhaps a flaky-CI-test or something. But it all looks good now to me

@mikehardy mikehardy removed the Workflow: Waiting for User Response Blocked waiting for user response. label Jul 19, 2022
@mikehardy mikehardy merged commit 71dee2b into invertase:main Jul 19, 2022
@mikehardy mikehardy removed the Workflow: Pending Merge Waiting on CI or similar label Jul 19, 2022
@ken0nek ken0nek deleted the work/UNNotificationPresentationOption-config branch September 8, 2022 18:52
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.

2 participants