Skip to content

Commit

Permalink
patch: add on new intent override plugin for expo android
Browse files Browse the repository at this point in the history
  • Loading branch information
f0wu5u committed Sep 18, 2024
1 parent 253d9fe commit 1a3ba77
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
3 changes: 3 additions & 0 deletions expo/withAppsFlyer.js
Original file line number Diff line number Diff line change
@@ -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;
};
32 changes: 32 additions & 0 deletions expo/withAppsFlyerAndroid.js
Original file line number Diff line number Diff line change
@@ -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
})
}

0 comments on commit 1a3ba77

Please sign in to comment.