From 17cf05c5f3b96b64d0f8e64559928ac912274eb3 Mon Sep 17 00:00:00 2001 From: Samuel Newman Date: Thu, 27 Feb 2025 13:24:20 +0000 Subject: [PATCH] add copy link to native share menu --- src/components/post-ctrls/PostMenuItems.tsx | 6 +-- src/components/post-ctrls/ShareMenuItems.tsx | 50 +++++++++++++++++--- 2 files changed, 47 insertions(+), 9 deletions(-) diff --git a/src/components/post-ctrls/PostMenuItems.tsx b/src/components/post-ctrls/PostMenuItems.tsx index 9410882c32..979d7a4a06 100644 --- a/src/components/post-ctrls/PostMenuItems.tsx +++ b/src/components/post-ctrls/PostMenuItems.tsx @@ -1,4 +1,4 @@ -import React, {memo} from 'react' +import {memo, useMemo} from 'react' import { Platform, type PressableProps, @@ -136,7 +136,7 @@ let PostMenuItems = ({ const postUri = post.uri const postCid = post.cid const postAuthor = useProfileShadow(post.author) - const quoteEmbed = React.useMemo(() => { + const quoteEmbed = useMemo(() => { if (!currentAccount || !post.embed) return return getMaybeDetachedQuoteEmbed({ viewerDid: currentAccount.did, @@ -170,7 +170,7 @@ let PostMenuItems = ({ rootPostUri: rootUri, }) - const href = React.useMemo(() => { + const href = useMemo(() => { const urip = new AtUri(postUri) return makeProfileLink(postAuthor, 'post', urip.rkey) }, [postUri, postAuthor]) diff --git a/src/components/post-ctrls/ShareMenuItems.tsx b/src/components/post-ctrls/ShareMenuItems.tsx index 82c40f058b..37e94389cf 100644 --- a/src/components/post-ctrls/ShareMenuItems.tsx +++ b/src/components/post-ctrls/ShareMenuItems.tsx @@ -1,4 +1,5 @@ import {memo, useMemo} from 'react' +import * as ExpoClipboard from 'expo-clipboard' import {AtUri} from '@atproto/api' import {msg, Trans} from '@lingui/macro' import {useLingui} from '@lingui/react' @@ -10,14 +11,16 @@ import {shareText, shareUrl} from '#/lib/sharing' import {toShareUrl} from '#/lib/strings/url-helpers' import {useProfileShadow} from '#/state/cache/profile-shadow' import {useSession} from '#/state/session' +import * as Toast from '#/view/com/util/Toast' import {useDialogControl} from '#/components/Dialog' import {SendViaChatDialog} from '#/components/dms/dialogs/ShareViaChatDialog' +import {ArrowOutOfBox_Stroke2_Corner0_Rounded as ArrowOutOfBoxIcon} from '#/components/icons/ArrowOutOfBox' +import {ChainLink_Stroke2_Corner0_Rounded as ChainLinkIcon} from '#/components/icons/ChainLink' import {Clipboard_Stroke2_Corner2_Rounded as ClipboardIcon} from '#/components/icons/Clipboard' import {PaperPlane_Stroke2_Corner0_Rounded as Send} from '#/components/icons/PaperPlane' import * as Menu from '#/components/Menu' import * as Prompt from '#/components/Prompt' import {useDevMode} from '#/storage/hooks/dev-mode' -import {ArrowOutOfBox_Stroke2_Corner0_Rounded as ArrowOutOfBoxIcon} from '../icons/ArrowOutOfBox' import {type ShareMenuItemsProps} from './ShareMenuItems.types' let ShareMenuItems = ({ @@ -27,7 +30,8 @@ let ShareMenuItems = ({ const {hasSession, currentAccount} = useSession() const {_} = useLingui() const navigation = useNavigation() - const loggedOutWarningPromptControl = useDialogControl() + const pwiWarningShareControl = useDialogControl() + const pwiWarningCopyControl = useDialogControl() const sendViaChatControl = useDialogControl() const [devModeEnabled] = useDevMode() @@ -54,6 +58,14 @@ let ShareMenuItems = ({ onShareProp() } + const onCopyLink = () => { + const url = toShareUrl(href) + ExpoClipboard.setUrlAsync(url).then(() => + Toast.show(_(msg`Copied to clipboard`), 'clipboard-check'), + ) + onShareProp() + } + const onSelectChatToShareTo = (conversation: string) => { navigation.navigate('MessagesConversation', { conversation, @@ -75,20 +87,36 @@ let ShareMenuItems = ({ { if (showLoggedOutWarning) { - loggedOutWarningPromptControl.open() + pwiWarningShareControl.open() } else { onSharePost() } }}> - Share post + Share via... + { + if (showLoggedOutWarning) { + pwiWarningCopyControl.open() + } else { + onCopyLink() + } + }}> + + Copy link to post + + + + {hasSession && ( + +