Skip to content

Commit 8e5924e

Browse files
authored
Merge pull request Expensify#66100 from nyomanjyotisa/issue-65536
Add scan shortcut when long-pressing green plus button
2 parents 66ec904 + 2d25aac commit 8e5924e

2 files changed

Lines changed: 39 additions & 3 deletions

File tree

src/components/FloatingActionButton.tsx

Lines changed: 26 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,19 @@ 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+
103+
// Drop focus to avoid blue focus ring.
104+
fabPressable.current?.blur();
105+
onLongPress?.(event);
106+
};
107+
91108
return (
92109
<EducationalTooltip
93110
shouldRender={shouldShowProductTrainingTooltip}
@@ -108,10 +125,16 @@ function FloatingActionButton({onPress, isActive, accessibilityLabel, role, isTo
108125
buttonRef.current = el ?? null;
109126
}
110127
}}
111-
style={[styles.h100, styles.navigationTabBarItem]}
128+
style={[
129+
styles.h100,
130+
styles.navigationTabBarItem,
131+
132+
// Prevent text selection on touch devices (e.g. on long press)
133+
canUseTouchScreen() && styles.userSelectNone,
134+
]}
112135
accessibilityLabel={accessibilityLabel}
113136
onPress={toggleFabAction}
114-
onLongPress={() => {}}
137+
onLongPress={longPressFabAction}
115138
role={role}
116139
shouldUseHapticsOnLongPress={false}
117140
testID="floating-action-button"

src/pages/home/sidebar/FloatingActionButtonAndPopover.tsx

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

209+
const startScan = useCallback(() => {
210+
interceptAnonymousUser(() => {
211+
if (shouldRedirectToExpensifyClassic) {
212+
setModalVisible(true);
213+
return;
214+
}
215+
216+
// Start the scan flow directly
217+
startMoneyRequest(CONST.IOU.TYPE.CREATE, generateReportID(), CONST.IOU.REQUEST_TYPE.SCAN, false);
218+
});
219+
}, [shouldRedirectToExpensifyClassic]);
220+
209221
/**
210222
* Check if LHN status changed from active to inactive.
211223
* Used to close already opened FAB menu when open any other pages (i.e. Press Command + K on web).
@@ -590,6 +602,7 @@ function FloatingActionButtonAndPopover({onHideCreateMenu, onShowCreateMenu, isT
590602
isActive={isCreateMenuActive}
591603
ref={fabRef}
592604
onPress={toggleCreateMenu}
605+
onLongPress={startScan}
593606
/>
594607
</View>
595608
);

0 commit comments

Comments
 (0)