-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: integrate custom links for android
- added `withAndroidMailQueriesAndWhatsappPackage` config for `mailto:` and `whatsapp:` custom link in webview to work on Android devices SVA-1047
- Loading branch information
1 parent
ac84794
commit 001f367
Showing
2 changed files
with
45 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
config-plugins/withAndroidMailQueriesAndWhatsappPackage.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// eslint-disable-next-line @typescript-eslint/no-var-requires | ||
const { withAndroidManifest } = require('@expo/config-plugins'); | ||
|
||
function addIntentToQuery({ mod, intent }) { | ||
const copyMod = { ...mod }; | ||
if (!copyMod.modResults.manifest.queries) { | ||
copyMod.modResults.manifest.queries = [{ intent: [] }]; | ||
} else if (!copyMod.modResults.manifest.queries[0]) { | ||
copyMod.modResults.manifest.queries = []; | ||
} | ||
|
||
copyMod.modResults.manifest.queries.push({ | ||
...(!intent.dataScheme && { package: [{ $: { 'android:name': intent.actionName } }] }), | ||
...(intent.dataScheme && { | ||
intent: { | ||
data: [{ $: { 'android:scheme': intent.dataScheme } }], | ||
action: [{ $: { 'android:name': intent.actionName } }] | ||
} | ||
}) | ||
}); | ||
|
||
return copyMod; | ||
} | ||
|
||
const withAndroidMailQueriesAndWhatsappPackage = (config) => { | ||
const mod = withAndroidManifest(config, (mod) => { | ||
let modified = addIntentToQuery({ | ||
mod, | ||
intent: { actionName: 'android.intent.action.SENDTO', dataScheme: 'mailto' } | ||
}); | ||
|
||
modified = addIntentToQuery({ | ||
mod, | ||
intent: { actionName: 'com.whatsapp' } | ||
}); | ||
|
||
return modified; | ||
}); | ||
|
||
return mod; | ||
}; | ||
|
||
module.exports = withAndroidMailQueriesAndWhatsappPackage; |