From e11f52ad966167123dfdd0fa2dbe1857b44a8831 Mon Sep 17 00:00:00 2001 From: Samuel Newman Date: Wed, 28 May 2025 12:42:11 +0300 Subject: [PATCH] fix external links in TextLink --- src/view/com/util/Link.tsx | 44 ++++++++++++++++---------------------- 1 file changed, 18 insertions(+), 26 deletions(-) diff --git a/src/view/com/util/Link.tsx b/src/view/com/util/Link.tsx index c92c41bddb..3a0bf6f6da 100644 --- a/src/view/com/util/Link.tsx +++ b/src/view/com/util/Link.tsx @@ -11,11 +11,7 @@ import { type ViewStyle, } from 'react-native' import {sanitizeUrl} from '@braintree/sanitize-url' -import { - StackActions, - useLinkBuilder, - useLinkProps, -} from '@react-navigation/native' +import {StackActions} from '@react-navigation/native' import { type DebouncedNavigationProp, @@ -51,7 +47,7 @@ interface Props extends React.ComponentProps { hoverStyle?: StyleProp noFeedback?: boolean asAnchor?: boolean - dataSet?: Object | undefined + dataSet?: any anchorNoUnderline?: boolean navigationAction?: 'push' | 'replace' | 'navigate' onPointerEnter?: () => void @@ -73,6 +69,7 @@ export const Link = memo(function Link({ onBeforePress, accessibilityActions, onAccessibilityAction, + dataSet: dataSetProp, ...props }: Props) { const t = useTheme() @@ -103,6 +100,14 @@ export const Link = memo(function Link({ {name: 'activate', label: title}, ] + const dataSet = useMemo(() => { + const ds = {...dataSetProp} + if (anchorNoUnderline) { + ds.noUnderline = 1 + } + return ds + }, [dataSetProp, anchorNoUnderline]) + if (noFeedback) { return ( @@ -133,17 +138,6 @@ export const Link = memo(function Link({ ) } - if (anchorNoUnderline) { - // @ts-ignore web only -prf - props.dataSet = props.dataSet || {} - // @ts-ignore web only -prf - props.dataSet.noUnderline = 1 - } - - if (title && !props.accessibilityLabel) { - props.accessibilityLabel = title - } - const Com = props.hoverStyle ? PressableWithHover : Pressable return ( {children ? children : {title || 'link'}} @@ -175,7 +172,7 @@ export const TextLink = memo(function TextLink({ disableMismatchWarning, navigationAction, anchorNoUnderline, - ...orgProps + ...props }: { testID?: string type?: TypographyVariant @@ -191,12 +188,6 @@ export const TextLink = memo(function TextLink({ anchorNoUnderline?: boolean onBeforePress?: () => void } & TextProps) { - const {buildAction} = useLinkBuilder() - const sanitized = sanitizeUrl(href) - const {onPress: _, ...props} = useLinkProps({ - href: sanitized, - action: buildAction(sanitized), - }) const navigation = useNavigationDeduped() const {openModal, closeModal} = useModalControls() const openLink = useOpenLink() @@ -286,8 +277,9 @@ export const TextLink = memo(function TextLink({ // @ts-ignore web only -prf hrefAttrs={hrefAttrs} // hack to get open in new tab to work on safari. without this, safari will open in a new window onPress={onPress} - {...props} - {...orgProps}> + accessibilityRole="link" + href={convertBskyAppUrlIfNeeded(sanitizeUrl(href))} + {...props}> {text} )