Skip to content

Commit b019b10

Browse files
committed
Merge branch 'master' of github.com:mvanroon/react-native-email-link
# Conflicts: # src/email-exception.js
2 parents fd45650 + e389b47 commit b019b10

File tree

5 files changed

+36
-19
lines changed

5 files changed

+36
-19
lines changed

index.android.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,6 @@ export async function openComposer(options = {}) {
4545
if (options.removeText) {
4646
text = '';
4747
}
48-
NativeModules.Email.compose(text, options.to, options.subject, options.body);
48+
NativeModules.Email.compose(text, options.to, options.subject, options.body && encodeURIComponent(options.body));
4949
return;
5050
}

index.d.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ export function openInbox({
44
message,
55
cancelLabel,
66
removeText,
7-
}: {
7+
}?: {
88
app?: string | null;
99
title?: string;
1010
message?: string;
1111
cancelLabel?: string;
1212
removeText?: boolean;
13-
}): Promise<void>;
13+
}): Promise<{ app: string; title: string; } | null>;
1414

1515
export function openComposer({
1616
app,
@@ -23,7 +23,7 @@ export function openComposer({
2323
bcc,
2424
subject,
2525
body,
26-
}: {
26+
}?: {
2727
app?: string | null;
2828
title?: string;
2929
message?: string;
@@ -34,7 +34,7 @@ export function openComposer({
3434
bcc?: string;
3535
subject?: string;
3636
body?: string;
37-
}): Promise<void>;
37+
}): Promise<{ app: string; title: string; } | null>;
3838

3939
export class EmailException {
4040
message: string;

index.ios.js

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,14 @@ const uriParams = {
9393
bcc: 'bcc',
9494
subject: 'subject',
9595
body: 'body'
96+
},
97+
superhuman: {
98+
path: 'compose',
99+
to: 'to',
100+
cc: 'cc',
101+
bcc: 'bcc',
102+
subject: 'subject',
103+
body: 'body'
96104
}
97105
}
98106

@@ -156,7 +164,7 @@ export function askAppChoice(
156164
cancelLabel = 'Cancel',
157165
removeText = false
158166
) {
159-
return new Promise(async resolve => {
167+
return new Promise(async (resolve, reject) => {
160168
let availableApps = [];
161169
for (let app in prefixes) {
162170
let avail = await isAppInstalled(app);
@@ -165,8 +173,11 @@ export function askAppChoice(
165173
}
166174
}
167175

168-
if (availableApps.length < 2) {
169-
return resolve(availableApps[0] || null);
176+
if (!availableApps.length) {
177+
return reject(new EmailException('No email apps available'));
178+
}
179+
if (availableApps.length === 1) {
180+
return resolve(availableApps[0]);
170181
}
171182

172183
let options = availableApps.map(app => titles[app]);
@@ -185,13 +196,11 @@ export function askAppChoice(
185196
return resolve(availableApps[buttonIndex]);
186197
}
187198
);
188-
189-
return;
190199
});
191200
}
192201

193202
/**
194-
* Returns the name of the app provided in the options object of the app selected by the user.
203+
* Returns the name of the app provided in the options object or the app selected by the user.
195204
* @param {{
196205
* app: string | undefined | null,
197206
* }} options
@@ -222,10 +231,6 @@ async function getApp(options) {
222231
app = await askAppChoice(title, message, cancelLabel, removeText);
223232
}
224233

225-
if (!app) {
226-
throw new EmailException('No email app found');
227-
}
228-
229234
return app;
230235
}
231236

@@ -242,7 +247,13 @@ async function getApp(options) {
242247
*/
243248
export async function openInbox(options = {}) {
244249
const app = await getApp(options);
245-
return Linking.openURL(prefixes[app]);
250+
251+
if (!app) {
252+
return null
253+
}
254+
255+
await Linking.openURL(prefixes[app]);
256+
return { app, title: titles[app] };
246257
}
247258

248259
/**
@@ -263,6 +274,11 @@ export async function openInbox(options = {}) {
263274
*/
264275
export async function openComposer(options) {
265276
const app = await getApp(options);
277+
278+
if (!app) {
279+
return null
280+
}
281+
266282
const params = getUrlParams(app, options);
267283
let prefix = prefixes[app];
268284

@@ -271,5 +287,6 @@ export async function openComposer(options) {
271287
prefix = 'mailto:';
272288
}
273289

274-
return Linking.openURL(`${prefix}${params}`);
290+
await Linking.openURL(`${prefix}${params}`);
291+
return { app, title: titles[app] };
275292
}

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-email-link",
3-
"version": "1.7.4",
3+
"version": "1.9.1",
44
"versionCode": 2,
55
"description": "Open the mail app of the user's choice",
66
"main": "index",

0 commit comments

Comments
 (0)