Skip to content

Commit dd9ca7e

Browse files
authored
Merge pull request #232 from callstackincubator/feat/shareModule
Add `Share` module
2 parents c00f02f + 7128d01 commit dd9ca7e

File tree

3 files changed

+119
-0
lines changed

3 files changed

+119
-0
lines changed

lib/js/src/share.js

Lines changed: 54 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/share.re

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
type content;
2+
type options;
3+
4+
[@bs.obj]
5+
external makeContent :
6+
(~title: string=?, ~message: string=?, ~url: string=?, unit) => content =
7+
"";
8+
9+
[@bs.obj]
10+
external makeOptions :
11+
(
12+
~subject: string=?,
13+
~tintColor: string=?,
14+
~excludedActivityTypes: array(string)=?,
15+
~dialogTitle: string=?
16+
) =>
17+
options =
18+
"";
19+
20+
[@bs.module "react-native"] [@bs.scope "Share"]
21+
external _share : (content, options) => Js.Promise.t(bool) = "share";
22+
23+
let share =
24+
(
25+
~content,
26+
~title=?,
27+
~subject=?,
28+
~tintColor=?,
29+
~excludedActivityTypes=?,
30+
~dialogTitle=?,
31+
(),
32+
) =>
33+
switch (content) {
34+
| `text(message) =>
35+
_share(
36+
makeContent(~message, ~title?, ()),
37+
makeOptions(
38+
~subject?,
39+
~tintColor?,
40+
~excludedActivityTypes?,
41+
~dialogTitle?,
42+
),
43+
)
44+
| `url(url) =>
45+
_share(
46+
makeContent(~url, ~title?, ()),
47+
makeOptions(
48+
~subject?,
49+
~tintColor?,
50+
~excludedActivityTypes?,
51+
~dialogTitle?,
52+
),
53+
)
54+
};

src/share.rei

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
let share:
2+
(
3+
~content: [< | `text(string) | `url(string)],
4+
~title: string=?,
5+
~subject: string=?,
6+
~tintColor: string=?,
7+
~excludedActivityTypes: array(string)=?,
8+
~dialogTitle: string=?,
9+
unit
10+
) =>
11+
Js.Promise.t(bool);

0 commit comments

Comments
 (0)