(null)
- const transitionToState = React.useCallback((nextState: State) => {
- if (nextTimeout.current) {
- clearTimeout(nextTimeout.current)
- nextTimeout.current = null
- }
- setState(nextState)
- }, [])
-
- const onReadyToShow = useNonReactiveCallback(() => {
- if (state === 'might-show') {
- transitionToState('showing')
- }
- })
-
- const onReadyToHide = useNonReactiveCallback(() => {
- if (state === 'might-hide') {
- transitionToState('hiding')
- nextTimeout.current = setTimeout(onHidingAnimationEnd, HIDE_DURATION)
- }
- })
-
- const onHidingAnimationEnd = useNonReactiveCallback(() => {
- if (state === 'hiding') {
- transitionToState('hidden')
- }
- })
-
- const onReceiveHover = useNonReactiveCallback(() => {
- prefetchIfNeeded()
- if (state === 'hidden') {
- transitionToState('might-show')
- nextTimeout.current = setTimeout(onReadyToShow, SHOW_DELAY)
- } else if (state === 'might-show') {
- // Do nothing
- } else if (state === 'showing') {
- // Do nothing
- } else if (state === 'might-hide') {
- transitionToState('showing')
- } else if (state === 'hiding') {
- transitionToState('showing')
- }
- })
-
- const onLoseHover = useNonReactiveCallback(() => {
- if (state === 'hidden') {
- // Do nothing
- } else if (state === 'might-show') {
- transitionToState('hidden')
- } else if (state === 'showing') {
- transitionToState('might-hide')
- nextTimeout.current = setTimeout(onReadyToHide, HIDE_DELAY)
- } else if (state === 'might-hide') {
- // Do nothing
- } else if (state === 'hiding') {
- // Do nothing
- }
- })
-
const onPointerEnterTarget = React.useCallback(() => {
- onReceiveHover()
- }, [onReceiveHover])
+ prefetchIfNeeded()
+ dispatch('hovered')
+ }, [prefetchIfNeeded])
const onPointerLeaveTarget = React.useCallback(() => {
- onLoseHover()
- }, [onLoseHover])
+ dispatch('unhovered')
+ }, [])
const onPointerEnterCard = React.useCallback(() => {
- onReceiveHover()
- }, [onReceiveHover])
+ dispatch('hovered')
+ }, [])
const onPointerLeaveCard = React.useCallback(() => {
- onLoseHover()
- }, [onLoseHover])
+ dispatch('unhovered')
+ }, [])
- const onDismiss = React.useCallback(() => {
- transitionToState('hidden')
- }, [transitionToState])
+ const onPress = React.useCallback(() => {
+ dispatch('pressed')
+ }, [])
+
+ const isVisible =
+ currentState.stage === 'showing' ||
+ currentState.stage === 'might-hide' ||
+ currentState.stage === 'hiding'
+
+ const animationStyle = {
+ animation:
+ currentState.stage === 'hiding'
+ ? `avatarHoverFadeOut ${HIDE_DURATION}ms both`
+ : `avatarHoverFadeIn ${SHOW_DURATION}ms both`,
+ }
return (
@@ -180,7 +233,7 @@ export function ProfileHoverCardInner(props: ProfileHoverCardProps) {
style={floatingStyles}
onPointerEnter={onPointerEnterCard}
onPointerLeave={onPointerLeaveCard}>
-
+