Skip to content

Commit

Permalink
feat: integrate custom links for android
Browse files Browse the repository at this point in the history
- added `withAndroidMailQueriesAndWhatsappPackage` config for `mailto:` and `whatsapp:` custom
  link in webview to work on Android devices

SVA-1047
  • Loading branch information
ardasnturk committed Jul 3, 2023
1 parent ac84794 commit 001f367
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
3 changes: 2 additions & 1 deletion app.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@
"initialOrientation": "PORTRAIT"
}
],
"sentry-expo"
"sentry-expo",
"./config-plugins/withAndroidMailQueriesAndWhatsappPackage"
]
}
}
43 changes: 43 additions & 0 deletions config-plugins/withAndroidMailQueriesAndWhatsappPackage.js
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;

0 comments on commit 001f367

Please sign in to comment.