Skip to content

Commit cde1d34

Browse files
committed
Add scan shortcut when long-pressing green plus button
1 parent 33020e7 commit cde1d34

2 files changed

Lines changed: 36 additions & 3 deletions

File tree

src/components/FloatingActionButton.tsx

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import useOnyx from '@hooks/useOnyx';
88
import useResponsiveLayout from '@hooks/useResponsiveLayout';
99
import useTheme from '@hooks/useTheme';
1010
import useThemeStyles from '@hooks/useThemeStyles';
11+
import {canUseTouchScreen} from '@libs/DeviceCapabilities';
1112
import useIsHomeRouteActive from '@navigation/helpers/useIsHomeRouteActive';
1213
import variables from '@styles/variables';
1314
import 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"

src/pages/home/sidebar/FloatingActionButtonAndPopover.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,17 @@ function FloatingActionButtonAndPopover({onHideCreateMenu, onShowCreateMenu, isT
206206
[quickActionReport?.policyID],
207207
);
208208

209+
const startScanOnLongPress = useCallback(() => {
210+
interceptAnonymousUser(() => {
211+
if (shouldRedirectToExpensifyClassic) {
212+
setModalVisible(true);
213+
return;
214+
}
215+
// Start the scan flow directly
216+
startMoneyRequest(CONST.IOU.TYPE.CREATE, generateReportID(), CONST.IOU.REQUEST_TYPE.SCAN, false);
217+
});
218+
}, [shouldRedirectToExpensifyClassic]);
219+
209220
/**
210221
* Check if LHN status changed from active to inactive.
211222
* Used to close already opened FAB menu when open any other pages (i.e. Press Command + K on web).
@@ -589,6 +600,7 @@ function FloatingActionButtonAndPopover({onHideCreateMenu, onShowCreateMenu, isT
589600
isActive={isCreateMenuActive}
590601
ref={fabRef}
591602
onPress={toggleCreateMenu}
603+
onLongPress={startScanOnLongPress}
592604
/>
593605
</View>
594606
);

0 commit comments

Comments
 (0)