mirror of https://git.lenooby09.tech/LeNooby09/social-app.git
at ruby-v 995 B view raw
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}