From 6723e43d0c43bf2d06e95533cb13cc1e830d9795 Mon Sep 17 00:00:00 2001 From: Hailey Date: Thu, 2 May 2024 11:59:43 -0700 Subject: [PATCH] handle focus/unfocus better --- src/components/dms/ActionsWrapper.web.tsx | 25 ++++++++++++++++------- src/components/dms/MessageMenu.tsx | 1 + 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/components/dms/ActionsWrapper.web.tsx b/src/components/dms/ActionsWrapper.web.tsx index 2593573b53..afd9353df4 100644 --- a/src/components/dms/ActionsWrapper.web.tsx +++ b/src/components/dms/ActionsWrapper.web.tsx @@ -1,5 +1,5 @@ import React from 'react' -import {StyleSheet, View} from 'react-native' +import {NativeSyntheticEvent, StyleSheet, View} from 'react-native' import {ChatBskyConvoDefs} from '@atproto-labs/api' import {atoms as a} from '#/alf' @@ -15,9 +15,10 @@ export function ActionsWrapper({ isFromSelf: boolean children: React.ReactNode }) { - const [showActions, setShowActions] = React.useState(false) - const menuControl = useMenuControl() + const viewRef = React.useRef(null) + + const [showActions, setShowActions] = React.useState(false) const onMouseEnter = React.useCallback(() => { setShowActions(true) @@ -27,13 +28,21 @@ export function ActionsWrapper({ setShowActions(false) }, []) + // We need to handle the `onFocus` separately because we want to know if there is a related target (the element + // that is losing focus). If there isn't that means the focus is coming from a dropdown that is now closed. + const onFocus = React.useCallback((e: NativeSyntheticEvent) => { + if (e.nativeEvent.relatedTarget == null) return + setShowActions(true) + }, []) + return ( + style={StyleSheet.flatten([a.flex_1, a.flex_row])} + ref={viewRef}> {isFromSelf && ( )} @@ -60,7 +70,8 @@ export function ActionsWrapper({ )} diff --git a/src/components/dms/MessageMenu.tsx b/src/components/dms/MessageMenu.tsx index c000265d53..38b9fbd233 100644 --- a/src/components/dms/MessageMenu.tsx +++ b/src/components/dms/MessageMenu.tsx @@ -21,6 +21,7 @@ export let MessageMenu = ({ }: { hideTrigger?: boolean triggerOpacity?: number + onTriggerPress?: () => void message: ChatBskyConvoDefs.MessageView control: Menu.MenuControlProps }): React.ReactNode => {