From 5f49d1a686af129d44a6321b7712bc8986f9baed Mon Sep 17 00:00:00 2001 From: Eric Bailey Date: Mon, 18 Dec 2023 15:22:37 -0600 Subject: [PATCH] Add share button to post controls --- src/view/com/util/post-ctrls/PostCtrls.tsx | 62 +++++++++++++++++++++- 1 file changed, 60 insertions(+), 2 deletions(-) diff --git a/src/view/com/util/post-ctrls/PostCtrls.tsx b/src/view/com/util/post-ctrls/PostCtrls.tsx index 414fb1e094..971eeef9fc 100644 --- a/src/view/com/util/post-ctrls/PostCtrls.tsx +++ b/src/view/com/util/post-ctrls/PostCtrls.tsx @@ -6,7 +6,8 @@ import { View, ViewStyle, } from 'react-native' -import {AppBskyFeedDefs, AppBskyFeedPost} from '@atproto/api' +import {AppBskyFeedDefs, AppBskyFeedPost, AtUri} from '@atproto/api' +import {FontAwesomeIcon} from '@fortawesome/react-native-fontawesome' import {Text} from '../text/Text' import {PostDropdownBtn} from '../forms/PostDropdownBtn' import {HeartIcon, HeartIconSolid, CommentBottomArrow} from 'lib/icons' @@ -26,6 +27,12 @@ import { import {useComposerControls} from '#/state/shell/composer' import {Shadow} from '#/state/cache/types' import {useRequireAuth} from '#/state/session' +import {NativeDropdown} from '#/view/com/util/forms/NativeDropdown' +import {EventStopper} from '#/view/com/util/EventStopper' +import {toShareUrl} from 'lib/strings/url-helpers' +import {shareUrl} from 'lib/sharing' +import {makeProfileLink} from '#/lib/routes/links' +import {isNative} from '#/platform/detection' let PostCtrls = ({ big, @@ -48,6 +55,14 @@ let PostCtrls = ({ const postRepostMutation = usePostRepostMutation() const postUnrepostMutation = usePostUnrepostMutation() const requireAuth = useRequireAuth() + const href = React.useMemo(() => { + const urip = new AtUri(post.uri) + return makeProfileLink( + {did: post.author.did, handle: post.author.handle}, + 'post', + urip.rkey, + ) + }, [post]) const defaultCtrlColor = React.useMemo( () => ({ @@ -128,6 +143,11 @@ let PostCtrls = ({ closeModal, ]) + const onPressShare = useCallback(() => { + const url = toShareUrl(href) + shareUrl(url) + }, [href]) + return ( ) : undefined} + + {isNative ? ( + + + + ) : ( + + + + + + + + )} + {big ? undefined : ( )} {/* used for adding pad to the right side */} - ) }