mirror of https://git.lenooby09.tech/LeNooby09/social-app.git
1import {Share} from 'react-native'
2// import * as Sharing from 'expo-sharing'
3import {setStringAsync} from 'expo-clipboard'
4
5import {isAndroid, isIOS} from 'platform/detection'
6import * as Toast from '#/view/com/util/Toast'
7
8/**
9 * This function shares a URL using the native Share API if available, or copies it to the clipboard
10 * and displays a toast message if not (mostly on web)
11 * @param {string} url - A string representing the URL that needs to be shared or copied to the
12 * clipboard.
13 */
14export async function shareUrl(url: string) {
15 if (isAndroid) {
16 await Share.share({message: url})
17 } else if (isIOS) {
18 await Share.share({url})
19 } else {
20 // React Native Share is not supported by web. Web Share API
21 // has increasing but not full support, so default to clipboard
22 setStringAsync(url)
23 Toast.show('Copied to clipboard')
24 }
25}