diff --git a/expo/withAppsFlyer.js b/expo/withAppsFlyer.js index b2b4a66c..58e60d16 100644 --- a/expo/withAppsFlyer.js +++ b/expo/withAppsFlyer.js @@ -1,5 +1,8 @@ const withAppsFlyerIos = require('./withAppsFlyerIos'); +const withAppsFlyerAndroid = require('./withAppsFlyerAndroid'); + module.exports = function withAppsFlyer(config, { shouldUseStrictMode = false }) { config = withAppsFlyerIos(config, shouldUseStrictMode); + config = withAppsFlyerAndroid(config) return config; }; diff --git a/expo/withAppsFlyerAndroid.js b/expo/withAppsFlyerAndroid.js new file mode 100644 index 00000000..125d1af3 --- /dev/null +++ b/expo/withAppsFlyerAndroid.js @@ -0,0 +1,32 @@ +const {withMainActivity} = require('@expo/config-plugins') + +function overrideOnNewIntent(contents, packageName = ''){ + let nextContent = contents + const intentImportString = 'import android.content.intent' + + if (!nextContent.includes(intentImportString)){ + const packageString = `${packageName}\n` + nextContent = nextContent.replace(packageString,`${packageString}\n${intentImportString}`) + } + + if (!nextContent.includes('override fun onNewIntent(intent: Intent?)')) { + const classDeclarationRegex = /class\s+\w+.*\{/ + nextContent = nextContent.replace( + classDeclarationRegex, + match=>`${match} + override fun onNewIntent(intent: Intent?) { + super.onNewIntent(intent) + setIntent(intent) + } +`) + } + return nextContent +} + +module.exports = function withAppsFlyerAndroid(config){ + return withMainActivity(config, function(config){ + const {modResults:{contents},android} = config + config.modResults.contents = overrideOnNewIntent(contents,android?.package) + return config + }) +}