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