Skip to content

Commit

Permalink
[expo-notifications][Android] adjust logic in handling responses when…
Browse files Browse the repository at this point in the history
… 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).
  • Loading branch information
douglowder committed Jun 12, 2024
1 parent a548eb3 commit 4fa2ec6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
2 changes: 2 additions & 0 deletions packages/expo-notifications/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

### 🐛 Bug fixes

- [Android] adjust logic in handling responses when app in background or killed ([#29659](https://github.com/expo/expo/pull/29659) by [@douglowder](https://github.com/douglowder)))
- [Android] Fix setBadgeCount() when badge count is 0. ([#29657](https://github.com/expo/expo/pull/29657) by [@douglowder](https://github.com/douglowder))
- [Android] Add default channel plugin prop, restore legacy icon and color. ([#29491](https://github.com/expo/expo/pull/29491) by [@douglowder](https://github.com/douglowder))
- Remove console.log line. ([#29443](https://github.com/expo/expo/pull/29443) by [@douglowder](https://github.com/douglowder))
- [Android] Remove unneeded logging. ([#29370](https://github.com/expo/expo/pull/29370) by [@douglowder](https://github.com/douglowder))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,16 +126,27 @@ public void onNotificationsDropped() {
}
}

public void onNotificationResponseFromExtras(Bundle extras) {
if (mPendingNotificationResponsesFromExtras.isEmpty()) {
mPendingNotificationResponsesFromExtras.add(extras);
} else {
public void onNotificationResponseFromExtras(Bundle extras) {
// We're going to be passed in extras from either
// a killed state (ExpoNotificationLifecycleListener::onCreate)
// OR a background state (ExpoNotificationLifecycleListener::onNewIntent)

// If we've just come from a background state, we'll have listeners set up
// pass on the notification to them
if (!mListenerReferenceMap.isEmpty()) {
for (WeakReference<NotificationListener> listenerReference : mListenerReferenceMap.values()) {
NotificationListener listener = listenerReference.get();
if (listener != null) {
listener.onNotificationResponseIntentReceived(extras);
}
}
} else {
// Otherwise, the app has been launched from a killed state, and our listeners
// haven't yet been setup. We'll add this to a list of pending notifications
// for them to process once they've been initialized.
if (mPendingNotificationResponsesFromExtras.isEmpty()) {
mPendingNotificationResponsesFromExtras.add(extras);
}
}
}
}

0 comments on commit 4fa2ec6

Please sign in to comment.