-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Add primary receipt scan option on mobile and web #72236
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
mountiny
merged 17 commits into
Expensify:main
from
callstack-internal:JKobrynski/72030-add-primary-receipt-scan-option
Oct 14, 2025
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
2c8e499
[WIP] implement the UI part
JKobrynski 7d4b12a
implement floating camera button
JKobrynski 2f82e06
align fab layout spacings with designs
JKobrynski 3c882f1
cleanup and simplify the code, add missing translations
JKobrynski e2c2b16
remove unnecessary code
JKobrynski 9b6aa57
compress plus-circle svg
JKobrynski 8551838
fix unit test, apply suggested change
JKobrynski 0e14f70
remove unnecessary border radius style
JKobrynski e746d55
move policyChatForActivePolicy logic to a useOnyx selector
JKobrynski e07e1f5
hide the floating camera button on narrow web displays
JKobrynski 2d92042
adjust popover position, update camera icon
JKobrynski 370e96b
change camera button distance from to edge to 16px
JKobrynski dbb51c0
fix floating camera buttons redundant render
JKobrynski dda4de8
display totals on the left if camera button is displayed
JKobrynski 5ce1bfb
left align the totals on all mobile devices
JKobrynski 210f7fd
fix create button keyboard focus, add press animation
JKobrynski 2c114ce
Merge branch 'main' into JKobrynski/72030-add-primary-receipt-scan-op…
JKobrynski File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,91 @@ | ||||||||
| import React, {useMemo} from 'react'; | ||||||||
| import {View} from 'react-native'; | ||||||||
| import type {OnyxEntry} from 'react-native-onyx'; | ||||||||
| import useLocalize from '@hooks/useLocalize'; | ||||||||
| import useOnyx from '@hooks/useOnyx'; | ||||||||
| import useTheme from '@hooks/useTheme'; | ||||||||
| import useThemeStyles from '@hooks/useThemeStyles'; | ||||||||
| import {startMoneyRequest} from '@libs/actions/IOU'; | ||||||||
| import {canUseTouchScreen} from '@libs/DeviceCapabilities'; | ||||||||
| import interceptAnonymousUser from '@libs/interceptAnonymousUser'; | ||||||||
| import Navigation from '@libs/Navigation/Navigation'; | ||||||||
| import {generateReportID, getWorkspaceChats} from '@libs/ReportUtils'; | ||||||||
| import {shouldRestrictUserBillableActions} from '@libs/SubscriptionUtils'; | ||||||||
| import variables from '@styles/variables'; | ||||||||
| import CONST from '@src/CONST'; | ||||||||
| import ONYXKEYS from '@src/ONYXKEYS'; | ||||||||
| import ROUTES from '@src/ROUTES'; | ||||||||
| import type * as OnyxTypes from '@src/types/onyx'; | ||||||||
| import {isEmptyObject} from '@src/types/utils/EmptyObject'; | ||||||||
| import Icon from './Icon'; | ||||||||
| import {Camera} from './Icon/Expensicons'; | ||||||||
| import {PressableWithoutFeedback} from './Pressable'; | ||||||||
|
|
||||||||
| const sessionSelector = (session: OnyxEntry<OnyxTypes.Session>) => ({email: session?.email, accountID: session?.accountID}); | ||||||||
|
|
||||||||
| function FloatingCameraButton() { | ||||||||
| const {textLight} = useTheme(); | ||||||||
| const styles = useThemeStyles(); | ||||||||
| const {translate} = useLocalize(); | ||||||||
|
|
||||||||
| const [activePolicyID] = useOnyx(ONYXKEYS.NVP_ACTIVE_POLICY_ID, {canBeMissing: true}); | ||||||||
| const [activePolicy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${activePolicyID}`, {canBeMissing: true}); | ||||||||
| const [session] = useOnyx(ONYXKEYS.SESSION, {canBeMissing: false, selector: sessionSelector}); | ||||||||
| const [allTransactionDrafts] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION_DRAFT, {canBeMissing: true}); | ||||||||
| const reportID = useMemo(() => generateReportID(), []); | ||||||||
|
|
||||||||
| const [policyChatForActivePolicy] = useOnyx(ONYXKEYS.COLLECTION.REPORT, { | ||||||||
| canBeMissing: true, | ||||||||
| selector: (reports) => { | ||||||||
| if (isEmptyObject(activePolicy) || !activePolicy?.isPolicyExpenseChatEnabled) { | ||||||||
| return undefined; | ||||||||
| } | ||||||||
| const policyChatsForActivePolicy = getWorkspaceChats(activePolicyID, [session?.accountID ?? CONST.DEFAULT_NUMBER_ID], reports); | ||||||||
| return policyChatsForActivePolicy.at(0); | ||||||||
| }, | ||||||||
|
Comment on lines
+39
to
+45
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The selectors should not be inline, can you refactor this to use stable reference to selector? |
||||||||
| }); | ||||||||
|
|
||||||||
| const onPress = () => { | ||||||||
| interceptAnonymousUser(() => { | ||||||||
| if (policyChatForActivePolicy?.policyID && shouldRestrictUserBillableActions(policyChatForActivePolicy.policyID)) { | ||||||||
| Navigation.navigate(ROUTES.RESTRICTED_ACTION.getRoute(policyChatForActivePolicy.policyID)); | ||||||||
| return; | ||||||||
| } | ||||||||
|
|
||||||||
| const quickActionReportID = policyChatForActivePolicy?.reportID ?? reportID; | ||||||||
| startMoneyRequest(CONST.IOU.TYPE.SUBMIT, quickActionReportID, CONST.IOU.REQUEST_TYPE.SCAN, true, undefined, allTransactionDrafts); | ||||||||
| }); | ||||||||
| }; | ||||||||
|
|
||||||||
| return ( | ||||||||
| <PressableWithoutFeedback | ||||||||
| style={[ | ||||||||
| styles.navigationTabBarFABItem, | ||||||||
| styles.ph0, | ||||||||
| // Prevent text selection on touch devices (e.g. on long press) | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
| canUseTouchScreen() && styles.userSelectNone, | ||||||||
| styles.floatingCameraButton, | ||||||||
| ]} | ||||||||
| accessibilityLabel={translate('sidebarScreen.fabScanReceiptExplained')} | ||||||||
| onPress={onPress} | ||||||||
| role={CONST.ROLE.BUTTON} | ||||||||
| testID="floating-camera-button" | ||||||||
| > | ||||||||
| <View | ||||||||
| style={styles.floatingActionButton} | ||||||||
| testID="floating-camera-button-container" | ||||||||
| > | ||||||||
| <Icon | ||||||||
| fill={textLight} | ||||||||
| src={Camera} | ||||||||
| width={variables.iconSizeNormal} | ||||||||
| height={variables.iconSizeNormal} | ||||||||
| /> | ||||||||
| </View> | ||||||||
| </PressableWithoutFeedback> | ||||||||
| ); | ||||||||
| } | ||||||||
|
|
||||||||
| FloatingCameraButton.displayName = 'FloatingCameraButton'; | ||||||||
|
|
||||||||
| export default FloatingCameraButton; | ||||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| import React, {useRef} from 'react'; | ||
| // eslint-disable-next-line no-restricted-imports | ||
|
JKobrynski marked this conversation as resolved.
|
||
| import type {GestureResponderEvent, Role, Text, View as ViewType} from 'react-native'; | ||
| import {View} from 'react-native'; | ||
| import useTheme from '@hooks/useTheme'; | ||
| import useThemeStyles from '@hooks/useThemeStyles'; | ||
| import {canUseTouchScreen} from '@libs/DeviceCapabilities'; | ||
| import variables from '@styles/variables'; | ||
| import Icon from './Icon'; | ||
| import {ReceiptPlus} from './Icon/Expensicons'; | ||
| import {PressableWithoutFeedback} from './Pressable'; | ||
|
|
||
| type FloatingReceiptButtonProps = { | ||
| /* Callback to fire on request to toggle the FloatingReceiptButton */ | ||
| onPress: (event: GestureResponderEvent | KeyboardEvent | undefined) => void; | ||
|
|
||
| /* An accessibility label for the button */ | ||
| accessibilityLabel: string; | ||
|
|
||
| /* An accessibility role for the button */ | ||
| role: Role; | ||
| }; | ||
|
|
||
| function FloatingReceiptButton({onPress, accessibilityLabel, role}: FloatingReceiptButtonProps) { | ||
| const {successHover, textLight} = useTheme(); | ||
| const styles = useThemeStyles(); | ||
| const borderRadius = styles.floatingActionButton.borderRadius; | ||
| const fabPressable = useRef<HTMLDivElement | ViewType | Text | null>(null); | ||
|
|
||
| const toggleFabAction = (event: GestureResponderEvent | KeyboardEvent | undefined) => { | ||
| // Drop focus to avoid blue focus ring. | ||
| fabPressable.current?.blur(); | ||
| onPress(event); | ||
| }; | ||
|
|
||
| return ( | ||
| <PressableWithoutFeedback | ||
| ref={(el) => { | ||
| fabPressable.current = el ?? null; | ||
| }} | ||
| style={[ | ||
| styles.navigationTabBarFABItem, | ||
|
|
||
| // Prevent text selection on touch devices (e.g. on long press) | ||
| canUseTouchScreen() && styles.userSelectNone, | ||
| ]} | ||
| accessibilityLabel={accessibilityLabel} | ||
| onPress={toggleFabAction} | ||
| role={role} | ||
| shouldUseHapticsOnLongPress | ||
| testID="floating-receipt-button" | ||
| > | ||
| {({hovered}) => ( | ||
| <View | ||
| style={[styles.floatingActionButton, {borderRadius}, styles.floatingActionButtonSmall, hovered && {backgroundColor: successHover}]} | ||
| testID="floating-receipt-button-container" | ||
| > | ||
| <Icon | ||
| fill={textLight} | ||
| src={ReceiptPlus} | ||
| width={variables.iconSizeSmall} | ||
| height={variables.iconSizeSmall} | ||
| /> | ||
| </View> | ||
| )} | ||
| </PressableWithoutFeedback> | ||
| ); | ||
| } | ||
|
|
||
| FloatingReceiptButton.displayName = 'FloatingReceiptButton'; | ||
|
|
||
| export default FloatingReceiptButton; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this not exist in the shared selectors? I would think it must exist