Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,51 @@ export const withExpoPluginFirebaseNotification: ConfigPlugin = config => {
});
};

// Helper function to get notification icon and color from either config.notification or expo-notifications plugin
const getNotificationConfig = (config: ExpoConfig) => {
// Check expo-notifications plugin
if (config.plugins) {
const expoNotificationsPlugin = config.plugins.find(plugin =>
Array.isArray(plugin) && plugin[0] === 'expo-notifications'
);

if (expoNotificationsPlugin && Array.isArray(expoNotificationsPlugin)) {
const pluginConfig = expoNotificationsPlugin[1];
if (pluginConfig && typeof pluginConfig === 'object') {
return {
icon: pluginConfig.icon,
color: pluginConfig.color,
};
}
}
}

/**
* @deprecated
* Get notification config from config.notification
* Will be removed in the future as `expo-notifications` plugin is the recommended way to configure notifications.
*/
if (config.notification) {
return {
icon: config.notification.icon,
color: config.notification.color,
};
}

return { icon: undefined, color: undefined };
};

export function setFireBaseMessagingAndroidManifest(
config: ExpoConfig,
application: ManifestApplication,
) {
// If the notification object is not defined, print a friendly warning
if (!config.notification) {
const { icon, color } = getNotificationConfig(config);
if (!icon) {
// 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
// eslint-disable-next-line no-console
console.warn(
'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',
);
return config;
}

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

if (
config.notification.icon &&
icon &&
!hasMetaData(application, 'com.google.firebase.messaging.default_notification_icon')
) {
// Expo will automatically create '@drawable/notification_icon' resource if you specify config.notification.icon.
Expand All @@ -59,7 +92,7 @@ export function setFireBaseMessagingAndroidManifest(
}

if (
config.notification.color &&
color &&
!hasMetaData(application, 'com.google.firebase.messaging.default_notification_color')
) {
metaData.push({
Expand Down