Skip to content

Commit ac96a96

Browse files
committed
feat(expo): enhances notification config retrieval
Improves notification configuration by first checking `expo-notifications` plugin for icon and color. Falls back to deprecated `config.notification` settings. Warns about missing notification icon for Android.
1 parent 9bf7aef commit ac96a96

File tree

1 file changed

+38
-5
lines changed

1 file changed

+38
-5
lines changed

packages/messaging/plugin/src/android/setupFirebaseNotifationIcon.ts

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,51 @@ export const withExpoPluginFirebaseNotification: ConfigPlugin = config => {
2626
});
2727
};
2828

29+
// Helper function to get notification icon and color from either config.notification or expo-notifications plugin
30+
const getNotificationConfig = (config: ExpoConfig) => {
31+
// Check expo-notifications plugin
32+
if (config.plugins) {
33+
const expoNotificationsPlugin = config.plugins.find(plugin =>
34+
Array.isArray(plugin) && plugin[0] === 'expo-notifications'
35+
);
36+
37+
if (expoNotificationsPlugin && Array.isArray(expoNotificationsPlugin)) {
38+
const pluginConfig = expoNotificationsPlugin[1];
39+
if (pluginConfig && typeof pluginConfig === 'object') {
40+
return {
41+
icon: pluginConfig.icon,
42+
color: pluginConfig.color,
43+
};
44+
}
45+
}
46+
}
47+
48+
/**
49+
* @deprecated
50+
* Get notification config from config.notification
51+
* Will be removed in the future as `expo-notifications` plugin is the recommended way to configure notifications.
52+
*/
53+
if (config.notification) {
54+
return {
55+
icon: config.notification.icon,
56+
color: config.notification.color,
57+
};
58+
}
59+
60+
return { icon: undefined, color: undefined };
61+
};
62+
2963
export function setFireBaseMessagingAndroidManifest(
3064
config: ExpoConfig,
3165
application: ManifestApplication,
3266
) {
33-
// If the notification object is not defined, print a friendly warning
34-
if (!config.notification) {
67+
const { icon, color } = getNotificationConfig(config);
68+
if (!icon) {
3569
// This warning is important because the notification icon can only use pure white on Android. By default, the system uses the app icon as the notification icon, but the app icon is usually not pure white, so you need to set the notification icon
3670
// eslint-disable-next-line no-console
3771
console.warn(
3872
'For Android 8.0 and above, it is necessary to set the notification icon to ensure correct display. Otherwise, the notification will not show the correct icon. For more information, visit https://docs.expo.dev/versions/latest/config/app/#notification',
3973
);
40-
return config;
4174
}
4275

4376
// Defensive code
@@ -46,7 +79,7 @@ export function setFireBaseMessagingAndroidManifest(
4679
const metaData = application['meta-data'];
4780

4881
if (
49-
config.notification.icon &&
82+
icon &&
5083
!hasMetaData(application, 'com.google.firebase.messaging.default_notification_icon')
5184
) {
5285
// Expo will automatically create '@drawable/notification_icon' resource if you specify config.notification.icon.
@@ -59,7 +92,7 @@ export function setFireBaseMessagingAndroidManifest(
5992
}
6093

6194
if (
62-
config.notification.color &&
95+
color &&
6396
!hasMetaData(application, 'com.google.firebase.messaging.default_notification_color')
6497
) {
6598
metaData.push({

0 commit comments

Comments
 (0)