don't underline handle in post meta (#3591)

* alignment

remove the unnecessary styles now

seriously?

flex-end everything

flex shrink

test

test

rm unneeded flex

flex the text

don't underline handle in post meta

* use `paddingLeft`

* use `paddingLeft` but with `4`

* Fix overflow color

* Use nbsp to make mobile work

---------

Co-authored-by: Dan Abramov <dan.abramov@gmail.com>
zio/stable
Hailey 2024-04-17 19:09:10 -07:00 committed by GitHub
parent 7e16276c04
commit 086dc93a7a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 43 additions and 31 deletions

View File

@ -2,34 +2,35 @@ import React, {ComponentProps, memo, useMemo} from 'react'
import { import {
GestureResponderEvent, GestureResponderEvent,
Platform, Platform,
Pressable,
StyleProp, StyleProp,
TextStyle,
TextProps, TextProps,
TextStyle,
TouchableOpacity,
View, View,
ViewStyle, ViewStyle,
Pressable,
TouchableOpacity,
} from 'react-native' } from 'react-native'
import {useLinkProps, StackActions} from '@react-navigation/native' import {sanitizeUrl} from '@braintree/sanitize-url'
import {Text} from './text/Text' import {StackActions, useLinkProps} from '@react-navigation/native'
import {TypographyVariant} from 'lib/ThemeContext'
import {router} from '../../../routes' import {useModalControls} from '#/state/modals'
import {useOpenLink} from '#/state/preferences/in-app-browser'
import {
DebouncedNavigationProp,
useNavigationDeduped,
} from 'lib/hooks/useNavigationDeduped'
import { import {
convertBskyAppUrlIfNeeded, convertBskyAppUrlIfNeeded,
isExternalUrl, isExternalUrl,
linkRequiresWarning, linkRequiresWarning,
} from 'lib/strings/url-helpers' } from 'lib/strings/url-helpers'
import {TypographyVariant} from 'lib/ThemeContext'
import {isAndroid, isWeb} from 'platform/detection' import {isAndroid, isWeb} from 'platform/detection'
import {sanitizeUrl} from '@braintree/sanitize-url'
import {PressableWithHover} from './PressableWithHover'
import {useModalControls} from '#/state/modals'
import {useOpenLink} from '#/state/preferences/in-app-browser'
import {WebAuxClickWrapper} from 'view/com/util/WebAuxClickWrapper' import {WebAuxClickWrapper} from 'view/com/util/WebAuxClickWrapper'
import {
DebouncedNavigationProp,
useNavigationDeduped,
} from 'lib/hooks/useNavigationDeduped'
import {useTheme} from '#/alf' import {useTheme} from '#/alf'
import {router} from '../../../routes'
import {PressableWithHover} from './PressableWithHover'
import {Text} from './text/Text'
type Event = type Event =
| React.MouseEvent<HTMLAnchorElement, MouseEvent> | React.MouseEvent<HTMLAnchorElement, MouseEvent>
@ -149,6 +150,7 @@ export const TextLink = memo(function TextLink({
onPress, onPress,
disableMismatchWarning, disableMismatchWarning,
navigationAction, navigationAction,
anchorNoUnderline,
...orgProps ...orgProps
}: { }: {
testID?: string testID?: string
@ -162,6 +164,7 @@ export const TextLink = memo(function TextLink({
title?: string title?: string
disableMismatchWarning?: boolean disableMismatchWarning?: boolean
navigationAction?: 'push' | 'replace' | 'navigate' navigationAction?: 'push' | 'replace' | 'navigate'
anchorNoUnderline?: boolean
} & TextProps) { } & TextProps) {
const {...props} = useLinkProps({to: sanitizeUrl(href)}) const {...props} = useLinkProps({to: sanitizeUrl(href)})
const navigation = useNavigationDeduped() const navigation = useNavigationDeduped()
@ -172,6 +175,11 @@ export const TextLink = memo(function TextLink({
console.error('Unable to detect mismatching label') console.error('Unable to detect mismatching label')
} }
if (anchorNoUnderline) {
dataSet = dataSet ?? {}
dataSet.noUnderline = 1
}
props.onPress = React.useCallback( props.onPress = React.useCallback(
(e?: Event) => { (e?: Event) => {
const requiresWarning = const requiresWarning =
@ -267,6 +275,7 @@ interface TextLinkOnWebOnlyProps extends TextProps {
navigationAction?: 'push' | 'replace' | 'navigate' navigationAction?: 'push' | 'replace' | 'navigate'
disableMismatchWarning?: boolean disableMismatchWarning?: boolean
onPointerEnter?: () => void onPointerEnter?: () => void
anchorNoUnderline?: boolean
} }
export const TextLinkOnWebOnly = memo(function DesktopWebTextLink({ export const TextLinkOnWebOnly = memo(function DesktopWebTextLink({
testID, testID,

View File

@ -35,6 +35,11 @@ let PostMeta = (opts: PostMetaOpts): React.ReactNode => {
const handle = opts.author.handle const handle = opts.author.handle
const prefetchProfileQuery = usePrefetchProfileQuery() const prefetchProfileQuery = usePrefetchProfileQuery()
const profileLink = makeProfileLink(opts.author)
const onPointerEnter = isWeb
? () => prefetchProfileQuery(opts.author.did)
: undefined
return ( return (
<View style={[styles.container, opts.style]}> <View style={[styles.container, opts.style]}>
{opts.showAvatar && ( {opts.showAvatar && (
@ -49,11 +54,10 @@ let PostMeta = (opts: PostMetaOpts): React.ReactNode => {
/> />
</View> </View>
)} )}
<View style={styles.maxWidth}> <Text numberOfLines={1} style={[styles.maxWidth, pal.textLight]}>
<TextLinkOnWebOnly <TextLinkOnWebOnly
type={opts.displayNameType || 'lg-bold'} type={opts.displayNameType || 'lg-bold'}
style={[pal.text, opts.displayNameStyle]} style={[pal.text, opts.displayNameStyle]}
numberOfLines={1}
lineHeight={1.2} lineHeight={1.2}
disableMismatchWarning disableMismatchWarning
text={ text={
@ -62,22 +66,21 @@ let PostMeta = (opts: PostMetaOpts): React.ReactNode => {
displayName, displayName,
opts.moderation?.ui('displayName'), opts.moderation?.ui('displayName'),
)} )}
&nbsp;
<Text
type="md"
numberOfLines={1}
lineHeight={1.2}
style={pal.textLight}>
{sanitizeHandle(handle, '@')}
</Text>
</> </>
} }
href={makeProfileLink(opts.author)} href={profileLink}
onPointerEnter={ onPointerEnter={onPointerEnter}
isWeb ? () => prefetchProfileQuery(opts.author.did) : undefined
}
/> />
</View> <TextLinkOnWebOnly
type="md"
disableMismatchWarning
style={[pal.textLight, {flexShrink: 4}]}
text={'\xa0' + sanitizeHandle(handle, '@')}
href={profileLink}
onPointerEnter={onPointerEnter}
anchorNoUnderline
/>
</Text>
{!isAndroid && ( {!isAndroid && (
<Text <Text
type="md" type="md"
@ -110,7 +113,7 @@ export {PostMeta}
const styles = StyleSheet.create({ const styles = StyleSheet.create({
container: { container: {
flexDirection: 'row', flexDirection: 'row',
alignItems: 'center', alignItems: 'flex-end',
paddingBottom: 2, paddingBottom: 2,
gap: 4, gap: 4,
zIndex: 1, zIndex: 1,