From 87c83dd00c30a225d225b2c7381f27bbf9ba2e6e Mon Sep 17 00:00:00 2001 From: Hailey Date: Tue, 1 Oct 2024 20:26:10 -0700 Subject: [PATCH] custom bottom sheet link --- src/components/BottomSheetLink.tsx | 92 +++++++++++++++++++ src/components/BottomSheetLink.web.tsx | 3 + src/components/Link.tsx | 46 +++++++++- .../ReportDialog/SelectLabelerView.tsx | 8 +- .../ReportDialog/SelectReportOptionView.tsx | 6 +- .../moderation/LabelsOnMeDialog.tsx | 35 +++---- 6 files changed, 164 insertions(+), 26 deletions(-) create mode 100644 src/components/BottomSheetLink.tsx create mode 100644 src/components/BottomSheetLink.web.tsx diff --git a/src/components/BottomSheetLink.tsx b/src/components/BottomSheetLink.tsx new file mode 100644 index 0000000000..6b9f4ebd96 --- /dev/null +++ b/src/components/BottomSheetLink.tsx @@ -0,0 +1,92 @@ +import React from 'react' +import {BlueskyBottomSheetPressable} from '@haileyok/bluesky-bottom-sheet' +import {StackActions, useNavigation} from '@react-navigation/native' + +import {NavigationProp} from '#/lib/routes/types' +import {flatten, useTheme} from '#/alf' +import {useDialogContext} from '#/components/Dialog' +import {useInteractionState} from '#/components/hooks/useInteractionState' +import {InlineLinkProps, useLink} from '#/components/Link' +import {Text} from '#/components/Typography' +import {router} from '#/routes' + +export function BottomSheetInlineLinkText({ + children, + to, + action = 'push', + disableMismatchWarning, + style, + onPress: outerOnPress, + label, + shareOnLongPress, + disableUnderline, + ...rest +}: InlineLinkProps) { + const t = useTheme() + const stringChildren = typeof children === 'string' + const navigation = useNavigation() + const dialog = useDialogContext() + + const {href, isExternal, onLongPress} = useLink({ + to, + displayText: stringChildren ? children : '', + action, + disableMismatchWarning, + onPress: outerOnPress, + shareOnLongPress, + }) + const { + state: pressed, + onIn: onPressIn, + onOut: onPressOut, + } = useInteractionState() + + const onPress = () => { + if (isExternal) { + return + } + + dialog.close() + + if (action === 'push') { + navigation.dispatch(StackActions.push(...router.matchPath(href))) + } else if (action === 'replace') { + navigation.dispatch(StackActions.replace(...router.matchPath(href))) + } else if (action === 'navigate') { + // @ts-ignore + navigation.navigate(...router.matchPath(href)) + } else { + throw Error('Unsupported navigator action.') + } + } + + const flattenedStyle = flatten(style) || {} + + // eslint-disable-next-line bsky-internal/avoid-unwrapped-text + return ( + + + {children} + + + ) +} diff --git a/src/components/BottomSheetLink.web.tsx b/src/components/BottomSheetLink.web.tsx new file mode 100644 index 0000000000..6bfb275c25 --- /dev/null +++ b/src/components/BottomSheetLink.web.tsx @@ -0,0 +1,3 @@ +import {Link as BottomSheetLink} from './Link' + +export {BottomSheetLink} diff --git a/src/components/Link.tsx b/src/components/Link.tsx index c80b9f3707..56d030b5df 100644 --- a/src/components/Link.tsx +++ b/src/components/Link.tsx @@ -23,6 +23,7 @@ import {shouldClickOpenNewTab} from '#/platform/urls' import {useModalControls} from '#/state/modals' import {useOpenLink} from '#/state/preferences/in-app-browser' import {atoms as a, flatten, TextStyleProp, useTheme, web} from '#/alf' +import {BottomSheetButton} from '#/components/BottomSheetButton' import {Button, ButtonProps} from '#/components/Button' import {useInteractionState} from '#/components/hooks/useInteractionState' import {Text, TextProps} from '#/components/Typography' @@ -103,17 +104,17 @@ export function useLink({ linkRequiresWarning(href, displayText), ) - if (requiresWarning) { + if (isWeb) { e.preventDefault() + } + if (requiresWarning) { openModal({ name: 'link-warning', text: displayText, href: href, }) } else { - e.preventDefault() - if (isExternal) { openLink(href) } else { @@ -241,6 +242,45 @@ export function Link({ ) } +export function BottomSheetLink({ + children, + to, + action = 'push', + onPress: outerOnPress, + download, + ...rest +}: LinkProps) { + const {href, isExternal, onPress} = useLink({ + to, + displayText: typeof children === 'string' ? children : '', + action, + onPress: outerOnPress, + }) + + return ( + + {children} + + ) +} + export type InlineLinkProps = React.PropsWithChildren< BaseLinkProps & TextStyleProp & Pick > & diff --git a/src/components/ReportDialog/SelectLabelerView.tsx b/src/components/ReportDialog/SelectLabelerView.tsx index f7a8139ea5..e62dc9910b 100644 --- a/src/components/ReportDialog/SelectLabelerView.tsx +++ b/src/components/ReportDialog/SelectLabelerView.tsx @@ -4,10 +4,10 @@ import {AppBskyLabelerDefs} from '@atproto/api' import {msg, Trans} from '@lingui/macro' import {useLingui} from '@lingui/react' -export {useDialogControl as useReportDialogControl} from '#/components/Dialog' import {getLabelingServiceTitle} from '#/lib/moderation' import {atoms as a, useBreakpoints, useTheme} from '#/alf' -import {Button, useButtonContext} from '#/components/Button' +import {BottomSheetButton} from '#/components/BottomSheetButton' +import {useButtonContext} from '#/components/Button' import {Divider} from '#/components/Divider' import * as LabelingServiceCard from '#/components/LabelingServiceCard' import {Text} from '#/components/Typography' @@ -39,12 +39,12 @@ export function SelectLabelerView({ {props.labelers.map(labeler => { return ( - + ) })} diff --git a/src/components/ReportDialog/SelectReportOptionView.tsx b/src/components/ReportDialog/SelectReportOptionView.tsx index 82ada250a6..9d97441915 100644 --- a/src/components/ReportDialog/SelectReportOptionView.tsx +++ b/src/components/ReportDialog/SelectReportOptionView.tsx @@ -5,7 +5,7 @@ import {msg, Trans} from '@lingui/macro' import {useLingui} from '@lingui/react' import {ReportOption, useReportOptions} from '#/lib/moderation/useReportOptions' -import {Link} from '#/components/Link' +import {BottomSheetLink} from '#/components/Link' import {DMCA_LINK} from '#/components/ReportDialog/const' export {useDialogControl as useReportDialogControl} from '#/components/Dialog' @@ -125,7 +125,7 @@ export function SelectReportOptionView({ ]}> Need to report a copyright violation? - View details - + )} diff --git a/src/components/moderation/LabelsOnMeDialog.tsx b/src/components/moderation/LabelsOnMeDialog.tsx index 33c0e63352..22eb406a00 100644 --- a/src/components/moderation/LabelsOnMeDialog.tsx +++ b/src/components/moderation/LabelsOnMeDialog.tsx @@ -14,6 +14,7 @@ import {useAgent, useSession} from '#/state/session' import * as Toast from '#/view/com/util/Toast' import {atoms as a, useBreakpoints, useTheme} from '#/alf' import {BottomSheetButton} from '#/components/BottomSheetButton' +import {BottomSheetInlineLinkText} from '#/components/BottomSheetLink' import {ButtonIcon, ButtonText} from '#/components/Button' import * as Dialog from '#/components/Dialog' import {InlineLinkText} from '#/components/Link' @@ -157,23 +158,25 @@ function Label({ - - {isSelfLabel ? ( + {isSelfLabel ? ( + This label was applied by you. - ) : ( - - Source:{' '} - control.close()}> - {sourceName} - - - )} - + + ) : ( + + + Source: {' '} + + control.close()}> + {sourceName} + + + )} )