-
Notifications
You must be signed in to change notification settings - Fork 51
/
index.js
69 lines (63 loc) · 1.74 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// @flow
/**
* Copyright (c) Garuda Labs, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*/
import * as Namespaces from 'hyperview/src/services/namespaces';
import type { Content, Options } from './types';
import type { DOMString, Element } from 'hyperview/src/types';
import { Share } from 'react-native';
const getContent = (
message: ?DOMString,
title: ?DOMString,
url: ?DOMString,
): ?Content => {
if (message) {
if (title && url) {
return { message, title, url };
} else if (title) {
return { message, title };
} else if (url) {
return { message, url };
}
return { message };
}
return null;
};
const getOptions = (dialogTitle: ?DOMString, subject: ?DOMString): Options => {
if (dialogTitle) {
if (subject) {
return { dialogTitle, subject };
}
return { dialogTitle };
}
return {};
};
export default {
action: 'share',
callback: (element: Element) => {
// This share API is based off https://facebook.github.io/react-native/docs/0.52/share
const dialogTitle: ?DOMString = element.getAttributeNS(
Namespaces.SHARE,
'dialog-title',
);
const message: ?DOMString = element.getAttributeNS(
Namespaces.SHARE,
'message',
);
const subject: ?DOMString = element.getAttributeNS(
Namespaces.SHARE,
'subject',
);
const title: ?DOMString = element.getAttributeNS(Namespaces.SHARE, 'title');
const url: ?DOMString = element.getAttributeNS(Namespaces.SHARE, 'url');
const content = getContent(message, title, url);
if (content) {
const options = getOptions(dialogTitle, subject);
Share.share(content, options);
}
},
};