bsky-app/src/lib/sharing.ts
Samuel Newman 27d712290a
Use appropriate icons for toasts (#4803)
* use appropriate icons for toasts

* use info for session expiry

* tweak size

* message -> safeMessage

---------

Co-authored-by: Samuel Newman <10959775+mozzius@users.noreply.github.com>
2024-07-23 15:01:04 +01:00

25 lines
884 B
TypeScript

import {Share} from 'react-native'
// import * as Sharing from 'expo-sharing'
import {setStringAsync} from 'expo-clipboard'
import {isAndroid, isIOS} from 'platform/detection'
import * as Toast from '#/view/com/util/Toast'
/**
* This function shares a URL using the native Share API if available, or copies it to the clipboard
* and displays a toast message if not (mostly on web)
* @param {string} url - A string representing the URL that needs to be shared or copied to the
* clipboard.
*/
export async function shareUrl(url: string) {
if (isAndroid) {
await Share.share({message: url})
} else if (isIOS) {
await Share.share({url})
} else {
// React Native Share is not supported by web. Web Share API
// has increasing but not full support, so default to clipboard
setStringAsync(url)
Toast.show('Copied to clipboard', 'clipboard-check')
}
}