Skip to content

Commit

Permalink
Reduce hovercard false positives, add them to display names and handl…
Browse files Browse the repository at this point in the history
…es (#3739)

* Don't trigger hovercards on scroll

* Add display name / handle hovercards

* Increase hovercard delay
  • Loading branch information
gaearon authored Apr 28, 2024
1 parent 74cd1d4 commit 3b4848b
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 36 deletions.
18 changes: 13 additions & 5 deletions src/components/ProfileHoverCard/index.web.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ type Action =
| 'unhovered-long-enough'
| 'finished-animating-hide'

const SHOW_DELAY = 400
const SHOW_DELAY = 500
const SHOW_DURATION = 300
const HIDE_DELAY = 150
const HIDE_DURATION = 150
const HIDE_DURATION = 200

export function ProfileHoverCardInner(props: ProfileHoverCardProps) {
const {refs, floatingStyles} = useFloating({
Expand Down Expand Up @@ -244,12 +244,20 @@ export function ProfileHoverCardInner(props: ProfileHoverCardProps) {
}
}, [prefetchProfileQuery, props.did])

const onPointerEnterTarget = React.useCallback(() => {
const didFireHover = React.useRef(false)
const onPointerMoveTarget = React.useCallback(() => {
prefetchIfNeeded()
dispatch('hovered-target')
// Conceptually we want something like onPointerEnter,
// but we want to ignore entering only due to scrolling.
// So instead we hover on the first onPointerMove.
if (!didFireHover.current) {
didFireHover.current = true
dispatch('hovered-target')
}
}, [prefetchIfNeeded])

const onPointerLeaveTarget = React.useCallback(() => {
didFireHover.current = false
dispatch('unhovered-target')
}, [])

Expand Down Expand Up @@ -280,7 +288,7 @@ export function ProfileHoverCardInner(props: ProfileHoverCardProps) {
return (
<div
ref={refs.setReference}
onPointerEnter={onPointerEnterTarget}
onPointerMove={onPointerMoveTarget}
onPointerLeave={onPointerLeaveTarget}
onMouseUp={onPress}
style={{
Expand Down
65 changes: 34 additions & 31 deletions src/view/com/util/PostMeta.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {sanitizeHandle} from 'lib/strings/handles'
import {niceDate} from 'lib/strings/time'
import {TypographyVariant} from 'lib/ThemeContext'
import {isAndroid, isWeb} from 'platform/detection'
import {ProfileHoverCard} from '#/components/ProfileHoverCard'
import {TextLinkOnWebOnly} from './Link'
import {Text} from './text/Text'
import {TimeElapsed} from './TimeElapsed'
Expand Down Expand Up @@ -58,37 +59,39 @@ let PostMeta = (opts: PostMetaOpts): React.ReactNode => {
/>
</View>
)}
<Text
numberOfLines={1}
style={[styles.maxWidth, pal.textLight, opts.displayNameStyle]}>
<TextLinkOnWebOnly
type={opts.displayNameType || 'lg-bold'}
style={[pal.text]}
lineHeight={1.2}
disableMismatchWarning
text={
<>
{sanitizeDisplayName(
displayName,
opts.moderation?.ui('displayName'),
)}
</>
}
href={profileLink}
onBeforePress={onBeforePress}
onPointerEnter={onPointerEnter}
/>
<TextLinkOnWebOnly
type="md"
disableMismatchWarning
style={[pal.textLight, {flexShrink: 4}]}
text={'\xa0' + sanitizeHandle(handle, '@')}
href={profileLink}
onBeforePress={onBeforePress}
onPointerEnter={onPointerEnter}
anchorNoUnderline
/>
</Text>
<ProfileHoverCard inline did={opts.author.did}>
<Text
numberOfLines={1}
style={[styles.maxWidth, pal.textLight, opts.displayNameStyle]}>
<TextLinkOnWebOnly
type={opts.displayNameType || 'lg-bold'}
style={[pal.text]}
lineHeight={1.2}
disableMismatchWarning
text={
<>
{sanitizeDisplayName(
displayName,
opts.moderation?.ui('displayName'),
)}
</>
}
href={profileLink}
onBeforePress={onBeforePress}
onPointerEnter={onPointerEnter}
/>
<TextLinkOnWebOnly
type="md"
disableMismatchWarning
style={[pal.textLight, {flexShrink: 4}]}
text={'\xa0' + sanitizeHandle(handle, '@')}
href={profileLink}
onBeforePress={onBeforePress}
onPointerEnter={onPointerEnter}
anchorNoUnderline
/>
</Text>
</ProfileHoverCard>
{!isAndroid && (
<Text
type="md"
Expand Down

0 comments on commit 3b4848b

Please sign in to comment.