@@ -8,6 +8,7 @@ import useOnyx from '@hooks/useOnyx';
88import useResponsiveLayout from '@hooks/useResponsiveLayout' ;
99import useTheme from '@hooks/useTheme' ;
1010import useThemeStyles from '@hooks/useThemeStyles' ;
11+ import { canUseTouchScreen } from '@libs/DeviceCapabilities' ;
1112import useIsHomeRouteActive from '@navigation/helpers/useIsHomeRouteActive' ;
1213import variables from '@styles/variables' ;
1314import CONST from '@src/CONST' ;
@@ -27,6 +28,9 @@ type FloatingActionButtonProps = {
2728 /* Callback to fire on request to toggle the FloatingActionButton */
2829 onPress : ( event : GestureResponderEvent | KeyboardEvent | undefined ) => void ;
2930
31+ /* Callback to fire on long press of the FloatingActionButton */
32+ onLongPress ?: ( event : GestureResponderEvent | KeyboardEvent | undefined ) => void ;
33+
3034 /* Current state (active or not active) of the component */
3135 isActive : boolean ;
3236
@@ -40,7 +44,7 @@ type FloatingActionButtonProps = {
4044 isTooltipAllowed : boolean ;
4145} ;
4246
43- function FloatingActionButton ( { onPress, isActive, accessibilityLabel, role, isTooltipAllowed} : FloatingActionButtonProps , ref : ForwardedRef < HTMLDivElement | View | Text > ) {
47+ function FloatingActionButton ( { onPress, onLongPress , isActive, accessibilityLabel, role, isTooltipAllowed} : FloatingActionButtonProps , ref : ForwardedRef < HTMLDivElement | View | Text > ) {
4448 const { success, buttonDefaultBG, textLight} = useTheme ( ) ;
4549 const styles = useThemeStyles ( ) ;
4650 const borderRadius = styles . floatingActionButton . borderRadius ;
@@ -88,6 +92,18 @@ function FloatingActionButton({onPress, isActive, accessibilityLabel, role, isTo
8892 onPress ( event ) ;
8993 } ;
9094
95+ const longPressFabAction = ( event : GestureResponderEvent | KeyboardEvent | undefined ) => {
96+ // Only execute on narrow layout - prevent event from firing on wide screens
97+ if ( ! shouldUseNarrowLayout ) {
98+ return ;
99+ }
100+
101+ hideProductTrainingTooltip ( ) ;
102+ // Drop focus to avoid blue focus ring.
103+ fabPressable . current ?. blur ( ) ;
104+ onLongPress ?.( event ) ;
105+ } ;
106+
91107 return (
92108 < EducationalTooltip
93109 shouldRender = { shouldShowProductTrainingTooltip }
@@ -108,10 +124,15 @@ function FloatingActionButton({onPress, isActive, accessibilityLabel, role, isTo
108124 buttonRef . current = el ?? null ;
109125 }
110126 } }
111- style = { [ styles . h100 , styles . navigationTabBarItem ] }
127+ style = { [
128+ styles . h100 ,
129+ styles . navigationTabBarItem ,
130+ // Prevent text selection on touch devices (e.g. on long press)
131+ canUseTouchScreen ( ) && styles . userSelectNone ,
132+ ] }
112133 accessibilityLabel = { accessibilityLabel }
113134 onPress = { toggleFabAction }
114- onLongPress = { ( ) => { } }
135+ onLongPress = { longPressFabAction }
115136 role = { role }
116137 shouldUseHapticsOnLongPress = { false }
117138 testID = "floating-action-button"
0 commit comments