forked from
jollywhoppers.com/witchsky.app
Bluesky app fork with some witchin' additions 馃挮
1import {Share} from 'react-native'
2// import * as Sharing from 'expo-sharing'
3import {setStringAsync} from 'expo-clipboard'
4// TODO: replace global i18n instance with one returned from useLingui -sfn
5import {t} from '@lingui/macro'
6
7import {isAndroid, isIOS} from '#/platform/detection'
8import * as Toast from '#/view/com/util/Toast'
9
10/**
11 * This function shares a URL using the native Share API if available, or copies it to the clipboard
12 * and displays a toast message if not (mostly on web)
13 * @param {string} url - A string representing the URL that needs to be shared or copied to the
14 * clipboard.
15 */
16export async function shareUrl(url: string) {
17 if (isAndroid) {
18 await Share.share({message: url})
19 } else if (isIOS) {
20 await Share.share({url})
21 } else {
22 // React Native Share is not supported by web. Web Share API
23 // has increasing but not full support, so default to clipboard
24 setStringAsync(url)
25 Toast.show(t`Copied to clipboard`, 'clipboard-check')
26 }
27}
28
29/**
30 * This function shares a text using the native Share API if available, or copies it to the clipboard
31 * and displays a toast message if not (mostly on web)
32 *
33 * @param {string} text - A string representing the text that needs to be shared or copied to the
34 * clipboard.
35 */
36export async function shareText(text: string) {
37 if (isAndroid || isIOS) {
38 await Share.share({message: text})
39 } else {
40 await setStringAsync(text)
41 Toast.show(t`Copied to clipboard`, 'clipboard-check')
42 }
43}