diff options
Diffstat (limited to 'src/view/com/util/Link.tsx')
-rw-r--r-- | src/view/com/util/Link.tsx | 40 |
1 files changed, 16 insertions, 24 deletions
diff --git a/src/view/com/util/Link.tsx b/src/view/com/util/Link.tsx index f45622488..b6c512b09 100644 --- a/src/view/com/util/Link.tsx +++ b/src/view/com/util/Link.tsx @@ -8,7 +8,6 @@ import { View, ViewStyle, Pressable, - TouchableWithoutFeedback, TouchableOpacity, } from 'react-native' import {useLinkProps, StackActions} from '@react-navigation/native' @@ -23,7 +22,6 @@ import { import {isAndroid, isWeb} from 'platform/detection' import {sanitizeUrl} from '@braintree/sanitize-url' import {PressableWithHover} from './PressableWithHover' -import FixedTouchableHighlight from '../pager/FixedTouchableHighlight' import {useModalControls} from '#/state/modals' import {useOpenLink} from '#/state/preferences/in-app-browser' import {WebAuxClickWrapper} from 'view/com/util/WebAuxClickWrapper' @@ -31,6 +29,7 @@ import { DebouncedNavigationProp, useNavigationDeduped, } from 'lib/hooks/useNavigationDeduped' +import {useTheme} from '#/alf' type Event = | React.MouseEvent<HTMLAnchorElement, MouseEvent> @@ -48,6 +47,7 @@ interface Props extends ComponentProps<typeof TouchableOpacity> { anchorNoUnderline?: boolean navigationAction?: 'push' | 'replace' | 'navigate' onPointerEnter?: () => void + onBeforePress?: () => void } export const Link = memo(function Link({ @@ -61,8 +61,10 @@ export const Link = memo(function Link({ accessible, anchorNoUnderline, navigationAction, + onBeforePress, ...props }: Props) { + const t = useTheme() const {closeModal} = useModalControls() const navigation = useNavigationDeduped() const anchorHref = asAnchor ? sanitizeUrl(href) : undefined @@ -70,6 +72,7 @@ export const Link = memo(function Link({ const onPress = React.useCallback( (e?: Event) => { + onBeforePress?.() if (typeof href === 'string') { return onPressInner( closeModal, @@ -81,41 +84,27 @@ export const Link = memo(function Link({ ) } }, - [closeModal, navigation, navigationAction, href, openLink], + [closeModal, navigation, navigationAction, href, openLink, onBeforePress], ) if (noFeedback) { - if (isAndroid) { - // workaround for Android not working well with left/right swipe gestures and TouchableWithoutFeedback - // https://github.com/callstack/react-native-pager-view/issues/424 - return ( - <FixedTouchableHighlight - testID={testID} - onPress={onPress} - // @ts-ignore web only -prf - href={asAnchor ? sanitizeUrl(href) : undefined} - accessible={accessible} - accessibilityRole="link" - {...props}> - <View style={style}> - {children ? children : <Text>{title || 'link'}</Text>} - </View> - </FixedTouchableHighlight> - ) - } return ( <WebAuxClickWrapper> - <TouchableWithoutFeedback + <Pressable testID={testID} onPress={onPress} accessible={accessible} accessibilityRole="link" - {...props}> + {...props} + android_ripple={{ + color: t.atoms.bg_contrast_25.backgroundColor, + }} + unstable_pressDelay={isAndroid ? 90 : undefined}> {/* @ts-ignore web only -prf */} <View style={style} href={anchorHref}> {children ? children : <Text>{title || 'link'}</Text>} </View> - </TouchableWithoutFeedback> + </Pressable> </WebAuxClickWrapper> ) } @@ -276,6 +265,7 @@ interface TextLinkOnWebOnlyProps extends TextProps { accessibilityHint?: string title?: string navigationAction?: 'push' | 'replace' | 'navigate' + disableMismatchWarning?: boolean onPointerEnter?: () => void } export const TextLinkOnWebOnly = memo(function DesktopWebTextLink({ @@ -287,6 +277,7 @@ export const TextLinkOnWebOnly = memo(function DesktopWebTextLink({ numberOfLines, lineHeight, navigationAction, + disableMismatchWarning, ...props }: TextLinkOnWebOnlyProps) { if (isWeb) { @@ -301,6 +292,7 @@ export const TextLinkOnWebOnly = memo(function DesktopWebTextLink({ lineHeight={lineHeight} title={props.title} navigationAction={navigationAction} + disableMismatchWarning={disableMismatchWarning} {...props} /> ) |