1 | import { UnavailabilityError } from 'expo-modules-core';
|
2 |
|
3 | import Sharing from './ExpoSharing';
|
4 |
|
5 | // @needsAudit
|
6 | export type SharingOptions = {
|
7 | /**
|
8 | * Sets `mimeType` for `Intent` *(Android only)*
|
9 | */
|
10 | mimeType?: string;
|
11 | /**
|
12 | * ([Uniform Type Identifier](https://developer.apple.com/library/archive/documentation/FileManagement/Conceptual/understanding_utis/understand_utis_conc/understand_utis_conc.html))
|
13 | * the type of the target file *(iOS only)*
|
14 | */
|
15 | UTI?: string;
|
16 | /**
|
17 | * Sets share dialog title *(Android and Web only)*
|
18 | */
|
19 | dialogTitle?: string;
|
20 | };
|
21 |
|
22 | // @needsAudit
|
23 | /**
|
24 | * Determine if the sharing API can be used in this app.
|
25 | * @return A promise that fulfills with `true` if the sharing API can be used, and `false` otherwise.
|
26 | */
|
27 | export async function isAvailableAsync(): Promise<boolean> {
|
28 | if (Sharing) {
|
29 | if (Sharing.isAvailableAsync) {
|
30 | return await Sharing.isAvailableAsync();
|
31 | }
|
32 | return true;
|
33 | }
|
34 |
|
35 | return false;
|
36 | }
|
37 |
|
38 | // @needsAudit
|
39 | /**
|
40 | * Opens action sheet to share file to different applications which can handle this type of file.
|
41 | * @param url Local file URL to share.
|
42 | * @param options A map of share options.
|
43 | */
|
44 | export async function shareAsync(url: string, options: SharingOptions = {}): Promise<object> {
|
45 | if (!Sharing || !Sharing.shareAsync) {
|
46 | throw new UnavailabilityError('Sharing', 'shareAsync');
|
47 | }
|
48 | return await Sharing.shareAsync(url, options);
|
49 | }
|