add copy link to native share menu
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import React, {memo} from 'react'
|
import {memo, useMemo} from 'react'
|
||||||
import {
|
import {
|
||||||
Platform,
|
Platform,
|
||||||
type PressableProps,
|
type PressableProps,
|
||||||
@@ -136,7 +136,7 @@ let PostMenuItems = ({
|
|||||||
const postUri = post.uri
|
const postUri = post.uri
|
||||||
const postCid = post.cid
|
const postCid = post.cid
|
||||||
const postAuthor = useProfileShadow(post.author)
|
const postAuthor = useProfileShadow(post.author)
|
||||||
const quoteEmbed = React.useMemo(() => {
|
const quoteEmbed = useMemo(() => {
|
||||||
if (!currentAccount || !post.embed) return
|
if (!currentAccount || !post.embed) return
|
||||||
return getMaybeDetachedQuoteEmbed({
|
return getMaybeDetachedQuoteEmbed({
|
||||||
viewerDid: currentAccount.did,
|
viewerDid: currentAccount.did,
|
||||||
@@ -170,7 +170,7 @@ let PostMenuItems = ({
|
|||||||
rootPostUri: rootUri,
|
rootPostUri: rootUri,
|
||||||
})
|
})
|
||||||
|
|
||||||
const href = React.useMemo(() => {
|
const href = useMemo(() => {
|
||||||
const urip = new AtUri(postUri)
|
const urip = new AtUri(postUri)
|
||||||
return makeProfileLink(postAuthor, 'post', urip.rkey)
|
return makeProfileLink(postAuthor, 'post', urip.rkey)
|
||||||
}, [postUri, postAuthor])
|
}, [postUri, postAuthor])
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import {memo, useMemo} from 'react'
|
import {memo, useMemo} from 'react'
|
||||||
|
import * as ExpoClipboard from 'expo-clipboard'
|
||||||
import {AtUri} from '@atproto/api'
|
import {AtUri} from '@atproto/api'
|
||||||
import {msg, Trans} from '@lingui/macro'
|
import {msg, Trans} from '@lingui/macro'
|
||||||
import {useLingui} from '@lingui/react'
|
import {useLingui} from '@lingui/react'
|
||||||
@@ -10,14 +11,16 @@ import {shareText, shareUrl} from '#/lib/sharing'
|
|||||||
import {toShareUrl} from '#/lib/strings/url-helpers'
|
import {toShareUrl} from '#/lib/strings/url-helpers'
|
||||||
import {useProfileShadow} from '#/state/cache/profile-shadow'
|
import {useProfileShadow} from '#/state/cache/profile-shadow'
|
||||||
import {useSession} from '#/state/session'
|
import {useSession} from '#/state/session'
|
||||||
|
import * as Toast from '#/view/com/util/Toast'
|
||||||
import {useDialogControl} from '#/components/Dialog'
|
import {useDialogControl} from '#/components/Dialog'
|
||||||
import {SendViaChatDialog} from '#/components/dms/dialogs/ShareViaChatDialog'
|
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 {Clipboard_Stroke2_Corner2_Rounded as ClipboardIcon} from '#/components/icons/Clipboard'
|
||||||
import {PaperPlane_Stroke2_Corner0_Rounded as Send} from '#/components/icons/PaperPlane'
|
import {PaperPlane_Stroke2_Corner0_Rounded as Send} from '#/components/icons/PaperPlane'
|
||||||
import * as Menu from '#/components/Menu'
|
import * as Menu from '#/components/Menu'
|
||||||
import * as Prompt from '#/components/Prompt'
|
import * as Prompt from '#/components/Prompt'
|
||||||
import {useDevMode} from '#/storage/hooks/dev-mode'
|
import {useDevMode} from '#/storage/hooks/dev-mode'
|
||||||
import {ArrowOutOfBox_Stroke2_Corner0_Rounded as ArrowOutOfBoxIcon} from '../icons/ArrowOutOfBox'
|
|
||||||
import {type ShareMenuItemsProps} from './ShareMenuItems.types'
|
import {type ShareMenuItemsProps} from './ShareMenuItems.types'
|
||||||
|
|
||||||
let ShareMenuItems = ({
|
let ShareMenuItems = ({
|
||||||
@@ -27,7 +30,8 @@ let ShareMenuItems = ({
|
|||||||
const {hasSession, currentAccount} = useSession()
|
const {hasSession, currentAccount} = useSession()
|
||||||
const {_} = useLingui()
|
const {_} = useLingui()
|
||||||
const navigation = useNavigation<NavigationProp>()
|
const navigation = useNavigation<NavigationProp>()
|
||||||
const loggedOutWarningPromptControl = useDialogControl()
|
const pwiWarningShareControl = useDialogControl()
|
||||||
|
const pwiWarningCopyControl = useDialogControl()
|
||||||
const sendViaChatControl = useDialogControl()
|
const sendViaChatControl = useDialogControl()
|
||||||
const [devModeEnabled] = useDevMode()
|
const [devModeEnabled] = useDevMode()
|
||||||
|
|
||||||
@@ -54,6 +58,14 @@ let ShareMenuItems = ({
|
|||||||
onShareProp()
|
onShareProp()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const onCopyLink = () => {
|
||||||
|
const url = toShareUrl(href)
|
||||||
|
ExpoClipboard.setUrlAsync(url).then(() =>
|
||||||
|
Toast.show(_(msg`Copied to clipboard`), 'clipboard-check'),
|
||||||
|
)
|
||||||
|
onShareProp()
|
||||||
|
}
|
||||||
|
|
||||||
const onSelectChatToShareTo = (conversation: string) => {
|
const onSelectChatToShareTo = (conversation: string) => {
|
||||||
navigation.navigate('MessagesConversation', {
|
navigation.navigate('MessagesConversation', {
|
||||||
conversation,
|
conversation,
|
||||||
@@ -75,20 +87,36 @@ let ShareMenuItems = ({
|
|||||||
<Menu.Group>
|
<Menu.Group>
|
||||||
<Menu.Item
|
<Menu.Item
|
||||||
testID="postDropdownShareBtn"
|
testID="postDropdownShareBtn"
|
||||||
label={_(msg`Copy link to post`)}
|
label={_(msg`Share via...`)}
|
||||||
onPress={() => {
|
onPress={() => {
|
||||||
if (showLoggedOutWarning) {
|
if (showLoggedOutWarning) {
|
||||||
loggedOutWarningPromptControl.open()
|
pwiWarningShareControl.open()
|
||||||
} else {
|
} else {
|
||||||
onSharePost()
|
onSharePost()
|
||||||
}
|
}
|
||||||
}}>
|
}}>
|
||||||
<Menu.ItemText>
|
<Menu.ItemText>
|
||||||
<Trans>Share post</Trans>
|
<Trans>Share via...</Trans>
|
||||||
</Menu.ItemText>
|
</Menu.ItemText>
|
||||||
<Menu.ItemIcon icon={ArrowOutOfBoxIcon} position="right" />
|
<Menu.ItemIcon icon={ArrowOutOfBoxIcon} position="right" />
|
||||||
</Menu.Item>
|
</Menu.Item>
|
||||||
|
|
||||||
|
<Menu.Item
|
||||||
|
testID="postDropdownShareBtn"
|
||||||
|
label={_(msg`Copy link to post`)}
|
||||||
|
onPress={() => {
|
||||||
|
if (showLoggedOutWarning) {
|
||||||
|
pwiWarningCopyControl.open()
|
||||||
|
} else {
|
||||||
|
onCopyLink()
|
||||||
|
}
|
||||||
|
}}>
|
||||||
|
<Menu.ItemText>
|
||||||
|
<Trans>Copy link to post</Trans>
|
||||||
|
</Menu.ItemText>
|
||||||
|
<Menu.ItemIcon icon={ChainLinkIcon} position="right" />
|
||||||
|
</Menu.Item>
|
||||||
|
|
||||||
{hasSession && (
|
{hasSession && (
|
||||||
<Menu.Item
|
<Menu.Item
|
||||||
testID="postDropdownSendViaDMBtn"
|
testID="postDropdownSendViaDMBtn"
|
||||||
@@ -130,7 +158,7 @@ let ShareMenuItems = ({
|
|||||||
</Menu.Outer>
|
</Menu.Outer>
|
||||||
|
|
||||||
<Prompt.Basic
|
<Prompt.Basic
|
||||||
control={loggedOutWarningPromptControl}
|
control={pwiWarningShareControl}
|
||||||
title={_(msg`Note about sharing`)}
|
title={_(msg`Note about sharing`)}
|
||||||
description={_(
|
description={_(
|
||||||
msg`This post is only visible to logged-in users. It won't be visible to people who aren't signed in.`,
|
msg`This post is only visible to logged-in users. It won't be visible to people who aren't signed in.`,
|
||||||
@@ -139,6 +167,16 @@ let ShareMenuItems = ({
|
|||||||
confirmButtonCta={_(msg`Share anyway`)}
|
confirmButtonCta={_(msg`Share anyway`)}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
<Prompt.Basic
|
||||||
|
control={pwiWarningCopyControl}
|
||||||
|
title={_(msg`Note about sharing`)}
|
||||||
|
description={_(
|
||||||
|
msg`This post is only visible to logged-in users. It won't be visible to people who aren't signed in.`,
|
||||||
|
)}
|
||||||
|
onConfirm={onCopyLink}
|
||||||
|
confirmButtonCta={_(msg`Copy anyway`)}
|
||||||
|
/>
|
||||||
|
|
||||||
<SendViaChatDialog
|
<SendViaChatDialog
|
||||||
control={sendViaChatControl}
|
control={sendViaChatControl}
|
||||||
onSelectChat={onSelectChatToShareTo}
|
onSelectChat={onSelectChatToShareTo}
|
||||||
|
|||||||
Reference in New Issue
Block a user