Apply notification icon settings of FCM on Android (#3113)

Co-authored-by: Hailey <me@haileyok.com>
zio/stable
Eiichi Yoshikawa 2024-03-07 03:24:08 +09:00 committed by GitHub
parent 5b8d116e33
commit f61d1e1f94
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 39 additions and 1 deletions

View File

@ -153,10 +153,11 @@ module.exports = function (config) {
'expo-notifications',
{
icon: './assets/icon-android-notification.png',
color: '#ffffff',
color: '#1185fe',
},
],
'./plugins/withAndroidManifestPlugin.js',
'./plugins/withAndroidManifestFCMIconPlugin.js',
'./plugins/withAndroidStylesWindowBackgroundPlugin.js',
'./plugins/shareExtension/withShareExtensions.js',
].filter(Boolean),

View File

@ -0,0 +1,37 @@
const {withAndroidManifest} = require('expo/config-plugins')
module.exports = function withAndroidManifestFCMIconPlugin(appConfig) {
return withAndroidManifest(appConfig, function (decoratedAppConfig) {
try {
function addOrModifyMetaData(metaData, name, resource) {
const elem = metaData.find(elem => elem.$['android:name'] === name)
if (elem === undefined) {
metaData.push({
$: {
'android:name': name,
'android:resource': resource,
},
})
} else {
elem.$['android:resource'] = resource
}
}
const androidManifest = decoratedAppConfig.modResults.manifest
const metaData = androidManifest.application[0]['meta-data']
addOrModifyMetaData(
metaData,
'com.google.firebase.messaging.default_notification_color',
'@color/notification_icon_color',
)
addOrModifyMetaData(
metaData,
'com.google.firebase.messaging.default_notification_icon',
'@drawable/notification_icon',
)
return decoratedAppConfig
} catch (e) {
console.error(`withAndroidManifestFCMIconPlugin failed`, e)
}
return decoratedAppConfig
})
}