Apply notification icon settings of FCM on Android (#3113)
Co-authored-by: Hailey <me@haileyok.com>
This commit is contained in:
		
							parent
							
								
									5b8d116e33
								
							
						
					
					
						commit
						f61d1e1f94
					
				
					 2 changed files with 39 additions and 1 deletions
				
			
		| 
						 | 
				
			
			@ -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),
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										37
									
								
								plugins/withAndroidManifestFCMIconPlugin.js
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										37
									
								
								plugins/withAndroidManifestFCMIconPlugin.js
									
										
									
									
									
										Normal 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
 | 
			
		||||
  })
 | 
			
		||||
}
 | 
			
		||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue