Skip to content

Commit 2ada035

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

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-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: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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 mainActivityClassString = 'class MainActivity : ReactActivity() {'
14+
nextContent = nextContent.replace(
15+
mainActivityClassString,
16+
`${mainActivityClassString}
17+
18+
override fun onNewIntent(intent: Intent?) {
19+
super.onNewIntent(intent)
20+
setIntent(intent)
21+
}
22+
`)
23+
}
24+
return nextContent
25+
}
26+
27+
module.exports = function withAppsFlyerAndroid(config){
28+
return withMainActivity(config, function(config){
29+
const {modResults:{contents},android} = config
30+
config.modResults.contents = overrideOnNewIntent(contents,android?.package)
31+
return config
32+
})
33+
}

0 commit comments

Comments
 (0)