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

Merge expo-notifications FCMv1 fixes to SDK 50 #29714

Merged
merged 9 commits into from
Jun 13, 2024

Conversation

douglowder
Copy link
Contributor

Why

We would like to provide the recent FCMv1 fixes for expo-notifications to SDK 50 customers, if possible.

How

Cherry picked the recent changes in expo-notifications from SDK 51.

This PR is to provide extra review and testing, before we actually merge these changes to SDK 50 and publish.

Test Plan

  • CI should pass
  • Run a test app using SDK 50 with these changes, and verify correct behavior

Checklist

lukmccall and others added 9 commits June 12, 2024 13:48
# Why

Fixes events not being sent to js because native code uses the incorrect emitter.
Closes ENG-11898.

# Test plan

- https://github.com/douglowder/NotificationsTest/tree/canary
- Fixes #24844
- Corrects an NPE that can happen if a deep link in the app is opened

- Change constants in the `expo-notifications` plugin to the correct
ones expected for FCMv1
- Add the recommended code to guard against NPE when logging Android
lifecycle events

- CI should pass
- Test app should show the correct icon and color in notification
banners

<!--
Please check the appropriate items below if they apply to your diff.
This is required for changes to Expo modules.
-->

- [ ] Documentation is up to date to reflect these changes (eg:
https://docs.expo.dev and README.md).
- [ ] Conforms with the [Documentation Writing Style
Guide](https://github.com/expo/expo/blob/main/guides/Expo%20Documentation%20Writing%20Style%20Guide.md)
- [ ] This diff will work correctly for `npx expo prebuild` & EAS Build
(eg: updated a module plugin).
After the fixes in #29204 , there are still reports of NPEs happening in
the notification lifecycle listener methods. These NPEs are coming from
code that causes Android to log events.

Remove the logging code that was causing the issue.

- CI should pass
- Test app should work, show correct icons in notifications, and
responses should show up even if app is killed

- [ ] Documentation is up to date to reflect these changes (eg:
https://docs.expo.dev and README.md).
- [ ] Conforms with the [Documentation Writing Style
Guide](https://github.com/expo/expo/blob/main/guides/Expo%20Documentation%20Writing%20Style%20Guide.md)
- [ ] This diff will work correctly for `npx expo prebuild` & EAS Build
(eg: updated a module plugin).
Remove a console.log call that was logging notification data.

CI should pass

<!--
Please check the appropriate items below if they apply to your diff.
This is required for changes to Expo modules.
-->

- [ ] Documentation is up to date to reflect these changes (eg:
https://docs.expo.dev and README.md).
- [ ] Conforms with the [Documentation Writing Style
Guide](https://github.com/expo/expo/blob/main/guides/Expo%20Documentation%20Writing%20Style%20Guide.md)
- [ ] This diff will work correctly for `npx expo prebuild` & EAS Build
(eg: updated a module plugin).
…e legacy icon and color (#29491)

Based on customer feedback from `expo-notifications@0.28.7`, three
adjustments are still needed:

- Set both FCM legacy and FCMv1 metadata items in the Android manifest,
so that icon and color work in both cases
- Add a config plugin property, `defaultChannel`, to allow a developer
to set the FCMv1 default channel in the manifest.
- The Android lifecycle listeners should check to see if the intent
extras have a `notificationResponse` object, and not map the intent
bundle to create a duplicate response in JS.

See [this
comment](#28656 (comment))
by @mgscreativa and other comments in that issue.

- Make the appropriate code changes in the plugin and in
`ExpoNotificationLifecycleListener.java`

- CI should pass
- Test app patched with these changes should behave as expected

<!--
Please check the appropriate items below if they apply to your diff.
This is required for changes to Expo modules.
-->

- [ ] Documentation is up to date to reflect these changes (eg:
https://docs.expo.dev and README.md).
- [ ] Conforms with the [Documentation Writing Style
Guide](https://github.com/expo/expo/blob/main/guides/Expo%20Documentation%20Writing%20Style%20Guide.md)
- [ ] This diff will work correctly for `npx expo prebuild` & EAS Build
(eg: updated a module plugin).
… 0 (#29657)

# Why

The `ShortcutBadger` package does not correctly set the badge count on
Android if the value to be set is 0. This fixes the issue, using a fix
provided by @haileyok in #29634 .

Fixes #29634.

# How

In the case where badge count is 0, use Android built in notification
manager to cancel all notifications.

# Test Plan

- CI should pass
- API should behave correctly in our test app

# Checklist

<!--
Please check the appropriate items below if they apply to your diff.
This is required for changes to Expo modules.
-->

- [ ] Documentation is up to date to reflect these changes (eg:
https://docs.expo.dev and README.md).
- [ ] Conforms with the [Documentation Writing Style
Guide](https://github.com/expo/expo/blob/main/guides/Expo%20Documentation%20Writing%20Style%20Guide.md)
- [ ] This diff will work correctly for `npx expo prebuild` & EAS Build
(eg: updated a module plugin).
… app in background or killed (#29659)

The logic in `onNotificationResponseFromExtras` needs to be adjusted to
correctly check whether response listeners are active, and do that check
first before falling back to add the response to the pending responses
(eventually used by `useLastNotificationResponse()` in JS).

See #28656 (comment)

Inverted the order of checks in the method.

- CI should pass
- Test the flows with the test app, using both expo-server-sdk tool and
expo.dev/notifications web tool

<!--
Please check the appropriate items below if they apply to your diff.
This is required for changes to Expo modules.
-->

- [ ] Documentation is up to date to reflect these changes (eg:
https://docs.expo.dev and README.md).
- [ ] Conforms with the [Documentation Writing Style
Guide](https://github.com/expo/expo/blob/main/guides/Expo%20Documentation%20Writing%20Style%20Guide.md)
- [ ] This diff will work correctly for `npx expo prebuild` & EAS Build
(eg: updated a module plugin).
@douglowder
Copy link
Contributor Author

Set up a branch of the microfoam test app for SDK 50 and built it with these changes.

Tests with FCMv1:

  • Notification listeners working
  • Notification response listeners working
  • Icon and color in notification banners
  • Last notification response hook works when app in background or killed
  • Background task works with data only notifications

@Simek
Copy link
Collaborator

Simek commented Jun 13, 2024

Would be nice to regenerate API documentation data JSON for SDK 50 from the sdk-50 branch you are targeting, so the docs reflects the changes which we plan to backport and ship.

@douglowder
Copy link
Contributor Author

ENG-12495

@douglowder
Copy link
Contributor Author

@Simek we are making no changes to the generated API data, only to the notifications.mdx page which is checked into the repo.

@douglowder douglowder merged commit f9fcd36 into sdk-50 Jun 13, 2024
12 of 13 checks passed
@douglowder douglowder deleted the doug/sdk-50-notifications branch June 13, 2024 18:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bot: fingerprint changed bot: passed checks ExpoBot has nothing to complain about
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants