Skip to content

Commit

Permalink
Add linter.
Browse files Browse the repository at this point in the history
  • Loading branch information
tschoffelen committed Mar 13, 2021
1 parent 7767df5 commit 512da1a
Show file tree
Hide file tree
Showing 14 changed files with 5,772 additions and 438 deletions.
11 changes: 11 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: Linting

on: [push]

jobs:
eslint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- run: yarn
- run: yarn lint
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ android/build/
.DS_Store
*.iml
local.properties
package-lock.json
1 change: 1 addition & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
133 changes: 66 additions & 67 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@ on their device.

Currently supported apps:

* Apple Mail
* Gmail
* Inbox
* Spark
* Airmail
* Outlook
* Yahoo Mail
* Superhuman

- Apple Mail
- Gmail
- Inbox
- Spark
- Airmail
- Outlook
- Yahoo Mail
- Superhuman

## Installation

Expand All @@ -25,6 +24,7 @@ This package works with autolinking on RN>=0.60. If you're using an earlier vers
check out the legacy [rnpm](https://github.com/leanmotherfuckers/react-native-email-link/tree/rnpm) branch.

### A note about iOS 9+

As of iOS 9, your app needs to provide the `LSApplicationQueriesSchemes` key inside
Info.plist to specify the URL schemes with which the app can interact.

Expand All @@ -50,9 +50,9 @@ Omitting these might mean that the library can't detect some of the mail apps in
### openInbox

```javascript
import { openInbox } from 'react-native-email-link'
import { openInbox } from "react-native-email-link";

openInbox()
openInbox();
```

#### Arguments
Expand All @@ -67,62 +67,61 @@ openInbox()

Text for the top of the ActionSheet or Intent.

| Type | Required | Default |
| -------- | -------- | --------------- |
| string | No | 'Open mail app' |
| Type | Required | Default |
| ------ | -------- | --------------- |
| string | No | 'Open mail app' |

#### `message`

Subtext under the title on the ActionSheet

| Type | Required | Default | Platform |
| -------- | -------- | ----------------------------------- | -------- |
| string | No | 'Which app would you like to open?' | iOS |
| Type | Required | Default | Platform |
| ------ | -------- | ----------------------------------- | -------- |
| string | No | 'Which app would you like to open?' | iOS |

#### `cancelLabel`

Text for last button of the ActionSheet.

| Type | Required | Default | Platform |
| -------- | -------- | --------- | -------- |
| string | No | 'Cancel' | iOS |
| Type | Required | Default | Platform |
| ------ | -------- | -------- | -------- |
| string | No | 'Cancel' | iOS |

#### `removeText`

If true, not text will be show above the ActionSheet or Intent. Default value is false.

| Type | Required | Default |
| -------- | -------- | -------- |
| boolean | No | false |
| Type | Required | Default |
| ------- | -------- | ------- |
| boolean | No | false |

#### `newTask`

If true, the email Intent will be started in a new Android task. Else, the Intent will be launched in the current task.

Read more about Android tasks [here](https://developer.android.com/guide/components/activities/tasks-and-back-stack).

| Type | Required | Default | Platform |
| -------- | -------- | --------- | -------- |
| boolean | No | true | Android |

| Type | Required | Default | Platform |
| ------- | -------- | ------- | -------- |
| boolean | No | true | Android |

#### Example

```javascript
import { openInbox } from 'react-native-email-link'
import { openInbox } from "react-native-email-link";

openInbox({
message: 'Whatcha wanna do?',
cancelLabel: 'Go back!'
})
message: "Whatcha wanna do?",
cancelLabel: "Go back!",
});
```

### openComposer

```javascript
import { openComposer } from 'react-native-email-link'
import { openComposer } from "react-native-email-link";

openComposer()
openComposer();
```

#### Arguments
Expand All @@ -142,73 +141,73 @@ openComposer()

Text for the top of the ActionSheet or Intent.

| Type | Required | Default |
| -------- | -------- | --------------- |
| string | No | 'Open mail app' |
| Type | Required | Default |
| ------ | -------- | --------------- |
| string | No | 'Open mail app' |

#### `message`

Subtext under the title on the ActionSheet.

| Type | Required | Default | Platform |
| -------- | -------- | ----------------------------------- | -------- |
| string | No | 'Which app would you like to open?' | iOS |
| Type | Required | Default | Platform |
| ------ | -------- | ----------------------------------- | -------- |
| string | No | 'Which app would you like to open?' | iOS |

#### `cancelLabel`

Text for last button of the ActionSheet.

| Type | Required | Default | Platform |
| -------- | -------- | --------- | -------- |
| string | No | 'Cancel' | iOS |
| Type | Required | Default | Platform |
| ------ | -------- | -------- | -------- |
| string | No | 'Cancel' | iOS |

#### `removeText`

If true, not text will be show above the ActionSheet or Intent. Default value is false.

| Type | Required | Default |
| -------- | -------- | -------- |
| boolean | No | false |
| Type | Required | Default |
| ------- | -------- | ------- |
| boolean | No | false |

#### `to`

Recipient's email address.

| Type | Required | Default |
| -------- | -------- | -------- |
| string | No | null |
| Type | Required | Default |
| ------ | -------- | ------- |
| string | No | null |

#### `cc`

Email's cc (iOS only).

| Type | Required | Default |
| -------- | -------- | -------- |
| string | No | null |
| Type | Required | Default |
| ------ | -------- | ------- |
| string | No | null |

#### `bcc`

Email's bcc (iOS only).

| Type | Required | Default |
| -------- | -------- | -------- |
| string | No | null |
| Type | Required | Default |
| ------ | -------- | ------- |
| string | No | null |

#### `subject`

Email's subject.

| Type | Required | Default |
| -------- | -------- | -------- |
| string | No | null |
| Type | Required | Default |
| ------ | -------- | ------- |
| string | No | null |

#### `body`

Email's body.

| Type | Required | Default |
| -------- | -------- | -------- |
| string | No | null |
| Type | Required | Default |
| ------ | -------- | ------- |
| string | No | null |

#### `encodeBody`

Expand All @@ -221,13 +220,13 @@ Apply `encodeURIComponent` to the email's body.
#### Example

```javascript
import { openComposer } from 'react-native-email-link'
import { openComposer } from "react-native-email-link";

openComposer({
to: '[email protected]',
subject: 'I have a question',
body: 'Hi, can you help me with...'
})
to: "[email protected]",
subject: "I have a question",
body: "Hi, can you help me with...",
});
```

## Authors
Expand All @@ -237,5 +236,5 @@ company like no other.

Contributors:

* Thomas Schoffelen, [@tschoffelen](https://twitter.com/tschoffelen)
* César Jeanroy, [@cesar3030](https://github.com/cesar3030)
- Thomas Schoffelen, [@tschoffelen](https://twitter.com/tschoffelen)
- César Jeanroy, [@cesar3030](https://github.com/cesar3030)
64 changes: 3 additions & 61 deletions index.android.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,65 +4,7 @@
* This file supports both iOS and Android.
*/

import { NativeModules } from 'react-native';
import { EmailException } from './src/email-exception';
export { EmailException };
import { openInbox, openComposer } from "./src/android";
import { EmailException } from "./src/email-exception";

/**
* Open an email app, or let the user choose what app to open.
*
* @param {{
* app: string | undefined | null,
* title: string,
* message: string,
* cancelLabel: string,
* }} options
*/
export async function openInbox(options = {}) {
// We can't pre-choose, since we use native intents
if (!('Email' in NativeModules)) {
throw new EmailException(
'NativeModules.Email does not exist. Check if you installed the Android dependencies correctly.'
);
}

let text = options.title || 'What app would you like to open?';
if (options.removeText) {
text = '';
}

let newTask = true;
if ('newTask' in options) {
newTask = Boolean(options.newTask);
}

NativeModules.Email.open(text, newTask);
return;
}

/**
* Open an email app on the compose screen, or let the user choose what app to open on the compose screen.
*
* @param {{
* title: string,
* removeText: boolean,
* to: string,
* subject: string,
* body: string,
* encodeBody: boolean
* }} options
*/
export async function openComposer(options = {}) {
let body = options.body || '';
let text = options.title || 'What app would you like to open?';
if (options.removeText) {
text = '';
}

if (options.encodeBody) {
body = encodeURIComponent(body);
}

NativeModules.Email.compose(text, options.to, options.subject || '', body);
return;
}
export { EmailException, openInbox, openComposer };
4 changes: 2 additions & 2 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export function openInbox({
message?: string;
cancelLabel?: string;
removeText?: boolean;
}): Promise<{ app: string; title: string; } | null>;
}): Promise<{ app: string; title: string } | null>;

export function openComposer({
app,
Expand All @@ -34,7 +34,7 @@ export function openComposer({
bcc?: string;
subject?: string;
body?: string;
}): Promise<{ app: string; title: string; } | null>;
}): Promise<{ app: string; title: string } | null>;

export class EmailException {
message: string;
Expand Down
Loading

0 comments on commit 512da1a

Please sign in to comment.