Skip to content

Commit 1a3ba77

Browse files
committed
patch: add on new intent override plugin for expo android
1 parent 253d9fe commit 1a3ba77

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

expo/withAppsFlyer.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
const withAppsFlyerIos = require('./withAppsFlyerIos');
2+
const withAppsFlyerAndroid = require('./withAppsFlyerAndroid');
3+
24
module.exports = function withAppsFlyer(config, { shouldUseStrictMode = false }) {
35
config = withAppsFlyerIos(config, shouldUseStrictMode);
6+
config = withAppsFlyerAndroid(config)
47
return config;
58
};

expo/withAppsFlyerAndroid.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
const {withMainActivity} = require('@expo/config-plugins')
2+
3+
function overrideOnNewIntent(contents, packageName = ''){
4+
let nextContent = contents
5+
const intentImportString = 'import android.content.intent'
6+
7+
if (!nextContent.includes(intentImportString)){
8+
const packageString = `${packageName}\n`
9+
nextContent = nextContent.replace(packageString,`${packageString}\n${intentImportString}`)
10+
}
11+
12+
if (!nextContent.includes('override fun onNewIntent(intent: Intent?)')) {
13+
const classDeclarationRegex = /class\s+\w+.*\{/
14+
nextContent = nextContent.replace(
15+
classDeclarationRegex,
16+
match=>`${match}
17+
override fun onNewIntent(intent: Intent?) {
18+
super.onNewIntent(intent)
19+
setIntent(intent)
20+
}
21+
`)
22+
}
23+
return nextContent
24+
}
25+
26+
module.exports = function withAppsFlyerAndroid(config){
27+
return withMainActivity(config, function(config){
28+
const {modResults:{contents},android} = config
29+
config.modResults.contents = overrideOnNewIntent(contents,android?.package)
30+
return config
31+
})
32+
}

0 commit comments

Comments
 (0)