Foreground Push Notification Conflict: Expo-notifications Vs. React-native-moengage Plugin Environment
Introduction
In this article, we will explore a conflict between two popular libraries in the Expo ecosystem: expo-notifications
and react-native-moengage
. When used together in an Expo managed project, these libraries can cause a conflict that prevents expo-notifications
from handling foreground push notifications on Android. We will delve into the issue, its diagnosis, and potential workarounds.
The Bug
When using expo-notifications
alongside react-native-moengage
in an Expo managed project, push notifications sent via FCM are not handled by expo-notifications
listeners (addNotificationReceivedListener
, setNotificationHandler
) when the app is in the foreground on Android. The addNotificationReceivedListener
callback does not fire, and the setNotificationHandler
does not result in a visible notification.
Background notifications (when the app is backgrounded or killed) are generally received by the system tray as expected. Taps on background notifications are correctly handled by addNotificationResponseReceivedListener
.
Comparison to Previous Bare React Native Setup
In a previous non-Expo project using bare React Native, we successfully used react-native-push-notification
alongside react-native-moengage
. In that setup:
- Both libraries had their respective FCM services declared in
AndroidManifest.xml
. react-native-push-notification
was configured with<meta-data android:name="com.dieam.reactnativepushnotification.notification_foreground" android:value="true"/>
.- Foreground push notifications were correctly received and handled by
react-native-push-notification's
listeners, allowing us to display them while the app was active.
Diagnosis / Suspected Cause
The react-native-moengage
Expo config plugin adds its own MoEFireBaseMessagingService
to the AndroidManifest.xml
to handle the com.google.firebase.MESSAGING_EVENT
. It appears this service intercepts the incoming FCM message when the app is foregrounded, preventing expo-notifications's
internal handlers from receiving the event.
Unlike react-native-push-notification
, expo-notifications
doesn't seem to have an equivalent manifest flag or mechanism to prioritize its handling, and react-native-moengage
does not provide a JavaScript listener for receiving foreground pushes (only for clicks), preventing a manual handoff.
Workaround Attempted
Manually modifying the MoEngage config plugin to not add the MoEFireBaseMessagingService
to the manifest does allow expo-notifications
to correctly handle foreground notifications. However, this breaks MoEngage's ability to handle notifications when the app is backgrounded or killed, as its essential service is missing.
Question
Is there a recommended approach within the Expo framework or expo-notifications
to handle scenarios where another library (like MoEngage via its config plugin) also registers a native FCM service? Is there a way to ensure expo-notifications
can still receive and handle foreground push events in this situation, similar to how it was possible with react-native-push-notification
in a bare RN setup?
Environment
expo-env-info 1.2.2 environment info:
System:
OS: macOS 15.3.1
Shell: 5.9 - /bin/zsh
Binaries:
Node: 23.10.0 - /opt/homebrew/bin/node
Yarn: 3.6.4 - /opt/homebrew/bin/yarn
npm: 10.9.2 - /opt/homebrew/bin/npm
Watchman: 2025.03.10.00 - /opt/homebrew/bin/watchman
Managers:
CocoaPods: 1.13.0 - /usr/local/bin/pod
SDKs:
iOS SDK:
Platforms: DriverKit 23.2, iOS 17.2, macOS 14.2, tvOS 17.2, visionOS 1.0, watchOS 10.2
IDEs:
Android Studio: 2021.1 AI-211.7628.21.2111.8309675
Xcode: 15.2/15C500b - /usr/bin/xcodebuild
npmPackages:
expo: ~52.0.37 => 52.0.44
expo-router: ~4.0.20 => 4.0.20
react: 18.3.1 => 18.3.1
react-dom: 18.3.1 => 18.3.1
react-native: 0.76.7 => 0.76.7
react-native-web: ~0.19.13 => 0.19.13
npmGlobalPackages:
eas-cli: 16.1.0
Expo Workflow: bare
Expo Doctor Diagnostics
No error
Conclusion
In this article, we have explored a conflict between expo-notifications
and react-native-moengage
in an Expo managed project. The conflict prevents expo-notifications
from handling foreground push notifications on Android. We have discussed the issue, its diagnosis, and potential workarounds. We have also highlighted the need for a recommended approach within the Expo framework or expo-notifications
to handle scenarios where another library also registers a native FCM service.
Q: What is the conflict between expo-notifications and react-native-moengage?
A: The conflict occurs when using expo-notifications alongside react-native-moengage in an Expo managed project. Push notifications sent via FCM are not handled by expo-notifications listeners (addNotificationReceivedListener, setNotificationHandler) when the app is in the foreground on Android.
Q: Why is this conflict happening?
A: The react-native-moengage Expo config plugin adds its own MoEFireBaseMessagingService to the AndroidManifest.xml to handle the com.google.firebase.MESSAGING_EVENT. This service intercepts the incoming FCM message when the app is foregrounded, preventing expo-notifications's internal handlers from receiving the event.
Q: Is this a known issue?
A: Yes, this is a known issue in the Expo community. Expo has acknowledged the issue and is working on a solution.
Q: What are the workarounds for this issue?
A: There are two workarounds for this issue:
- Manually modifying the MoEngage config plugin to not add the MoEFireBaseMessagingService to the manifest does allow expo-notifications to correctly handle foreground notifications. However, this breaks MoEngage's ability to handle notifications when the app is backgrounded or killed, as its essential service is missing.
- Using a different library that does not conflict with expo-notifications.
Q: Is there a recommended approach within the Expo framework or expo-notifications to handle scenarios where another library also registers a native FCM service?
A: Yes, Expo recommends using the expo-notifications library as the primary notification handler. If another library also registers a native FCM service, it is recommended to use a different library that does not conflict with expo-notifications.
Q: How can I ensure expo-notifications can still receive and handle foreground push events in this situation?
A: To ensure expo-notifications can still receive and handle foreground push events, you can use a different library that does not conflict with expo-notifications. Alternatively, you can manually modify the MoEngage config plugin to not add the MoEFireBaseMessagingService to the manifest.
Q: What are the implications of using a different library that does not conflict with expo-notifications?
A: Using a different library that does not conflict with expo-notifications may require additional configuration and setup. Additionally, it may not provide the same level of functionality as the original library.
Q: Is there a timeline for when this issue will be resolved?
A: Expo is working on a solution for this issue, but there is no official timeline for when it will be resolved.
Q: How can I stay up-to-date with the latest developments on this issue?
A: You can stay up-to-date with the latest developments on this issue by following the Expo community forums and documentation. Additionally, you can reach out to the Expo support team for further assistance.