Skip to content

Commit

Permalink
Add a config plugin for automatic setup with Expo
Browse files Browse the repository at this point in the history
  • Loading branch information
matt-oakes committed Oct 12, 2021
1 parent 87c3b9c commit 7d7a3a4
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 55 deletions.
31 changes: 11 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,33 +61,24 @@ Just add this in your `Info.plist` depending on which apps you'd like to support
<string>protonmail</string>
</array>
```

Using Expo? [Read the instructions](docs/expo.md) to make it work on iOS.

</details>

<details>
<summary><strong>AndroidUpdate AndroidManifest.xml</strong></summary>
<summary><strong>ExpoEnable Config Plugin</strong></summary>

When switching to Android 11/Android SDK 30 (i.e. using Expo SDK 41), this library doesn't work out of the box anymore. The reason is the new [Package Visibilty](https://developer.android.com/training/package-visibility) security feature. We'll have to update our `AndroidManifest.xml` to explicitly allow querying for other apps.
To allow the library to work with Expo you need to enable the [config plugin](https://docs.expo.dev/guides/config-plugins/). This plugin will automatically configure your Expo application with the correct settings for this library to function.

You can do so by coping the `<queries>` statement below, and pasting it in the top level of your AndroidManifest (i.e. within the `<manifest> ... </manifest>`).

```xml
<queries>
<intent>
<action android:name="android.intent.action.VIEW" />
<data android:scheme="mailto"/>
</intent>
</queries>
```
To enable the config plugin, add it to the `plugins` array inside your `app.config.js`/`app.config.json`. For example:

</details>
```json
{
"name": "my app",
"plugins": ["react-native-email-link"]
}

<details>
<summary><strong>Expo – Update app.json</strong></summary>
```

[Read the instructions here](docs/expo.md) to make it work on iOS.
Want this library to work on Android too? Because the library uses native code on Android you need to [follow Expo's guide](https://docs.expo.dev/workflow/customizing/) for custom native code.

</details>

Expand Down Expand Up @@ -297,6 +288,6 @@ Contributors:
</b>
<br>
<sub>
Custom consulting sessions availabe for implementation support or feature development.
Custom consulting sessions available for implementation support or feature development.
</sub>
</div>
7 changes: 7 additions & 0 deletions android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="agency.flexible.react.modules.email">
<!-- Required for react-native-email-link on Android 30+ -->
<queries>
<intent>
<action android:name="android.intent.action.VIEW" />
<data android:scheme="mailto"/>
</intent>
</queries>
</manifest>
1 change: 1 addition & 0 deletions app.plugin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require("./plugin/withEmailLink");
35 changes: 0 additions & 35 deletions docs/expo.md

This file was deleted.

48 changes: 48 additions & 0 deletions plugin/withEmailLink.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/**
* Adds the given query schemes to the infoPlist app config
*/
const withLSApplicationQueriesSchemes = (
config,
schemes
) => {
if (!config.ios) {
config.ios = {};
}
if (!config.ios.infoPlist) {
config.ios.infoPlist = {};
}
if (!Array.isArray(config.ios.infoPlist.LSApplicationQueriesSchemes)) {
config.ios.infoPlist.LSApplicationQueriesSchemes = [];
}

config.ios.infoPlist.LSApplicationQueriesSchemes = [
...new Set([
...config.ios.infoPlist.LSApplicationQueriesSchemes,
...schemes,
]),
];

return config;
};

/**
* Configures Expo
*/
const withEmailLink = (config) => {
config = withLSApplicationQueriesSchemes(config, [
"message",
"readdle-spark",
"airmail",
"ms-outlook",
"googlegmail",
"inbox-gmail",
"ymail",
"superhuman",
"yandexmail",
"fastmail",
"protonmail",
]);
return config;
};

exports.default = withEmailLink;

0 comments on commit 7d7a3a4

Please sign in to comment.