From 3e78c7101815985241b2631432a023dc8f70d82e Mon Sep 17 00:00:00 2001 From: Ollie Hsieh Date: Thu, 20 Apr 2023 11:08:30 -0700 Subject: [PATCH] Share profile and post (#499) --- src/view/com/profile/ProfileHeader.tsx | 16 +++++++++++++--- src/view/com/util/forms/DropdownButton.tsx | 14 +++++++++++++- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/src/view/com/profile/ProfileHeader.tsx b/src/view/com/profile/ProfileHeader.tsx index 4c232a13..e7597608 100644 --- a/src/view/com/profile/ProfileHeader.tsx +++ b/src/view/com/profile/ProfileHeader.tsx @@ -31,8 +31,9 @@ import {ProfileHeaderLabels} from '../util/moderation/ProfileHeaderLabels' import {usePalette} from 'lib/hooks/usePalette' import {useAnalytics} from 'lib/analytics' import {NavigationProp} from 'lib/routes/types' -import {isDesktopWeb} from 'platform/detection' +import {isAndroid, isDesktopWeb, isIOS} from 'platform/detection' import {FollowState} from 'state/models/cache/my-follows' +import Clipboard from '@react-native-clipboard/clipboard' const BACK_HITSLOP = {left: 30, top: 30, right: 30, bottom: 30} @@ -148,9 +149,18 @@ const ProfileHeaderLoaded = observer(function ProfileHeaderLoaded({ navigation.push('ProfileFollows', {name: view.handle}) }, [track, navigation, view]) - const onPressShare = React.useCallback(() => { + const onPressShare = React.useCallback(async () => { track('ProfileHeader:ShareButtonClicked') - Share.share({url: toShareUrl(`/profile/${view.handle}`)}) + const url = toShareUrl(`/profile/${view.handle}`) + + if (isIOS || isAndroid) { + 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 + Clipboard.setString(url) + Toast.show('Copied to clipboard') + } }, [track, view]) const onPressMuteAccount = React.useCallback(async () => { diff --git a/src/view/com/util/forms/DropdownButton.tsx b/src/view/com/util/forms/DropdownButton.tsx index 938c346c..f21323ef 100644 --- a/src/view/com/util/forms/DropdownButton.tsx +++ b/src/view/com/util/forms/DropdownButton.tsx @@ -19,6 +19,9 @@ import {toShareUrl} from 'lib/strings/url-helpers' import {useStores} from 'state/index' import {usePalette} from 'lib/hooks/usePalette' import {useTheme} from 'lib/ThemeContext' +import {isAndroid, isIOS} from 'platform/detection' +import Clipboard from '@react-native-clipboard/clipboard' +import * as Toast from '../../util/Toast' const HITSLOP = {left: 10, top: 10, right: 10, bottom: 10} const ESTIMATED_MENU_ITEM_HEIGHT = 52 @@ -159,7 +162,16 @@ export function PostDropdownBtn({ icon: 'share', label: 'Share...', onPress() { - Share.share({url: toShareUrl(itemHref)}) + const url = toShareUrl(itemHref) + + if (isIOS || isAndroid) { + 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 + Clipboard.setString(url) + Toast.show('Copied to clipboard') + } }, }, {