-
Notifications
You must be signed in to change notification settings - Fork 3.9k
feat: show full distance e-receipt on hover for map distance requests #92525
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 3 commits into
Expensify:main
from
software-mansion-labs:feat/zoom-map-e-receipts
Jun 8, 2026
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
52 changes: 52 additions & 0 deletions
52
src/components/ReportActionItem/HoveredDistanceEReceipt.tsx
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,52 @@ | ||
| import React, {useState} from 'react'; | ||
| import {View} from 'react-native'; | ||
| import type {LayoutChangeEvent} from 'react-native'; | ||
| import DistanceEReceipt from '@components/DistanceEReceipt'; | ||
| import useThemeStyles from '@hooks/useThemeStyles'; | ||
| import variables from '@styles/variables'; | ||
| import type {Transaction} from '@src/types/onyx'; | ||
|
|
||
| // The DistanceEReceipt panel is `variables.eReceiptBGHWidth` wide plus the 20px margin on each side (styles.m5). | ||
| const E_RECEIPT_CARD_WIDTH = variables.eReceiptBGHWidth + 40; | ||
|
|
||
| type HoveredDistanceEReceiptProps = { | ||
| /** The transaction for the distance expense */ | ||
| transaction: Transaction; | ||
| }; | ||
|
|
||
| function HoveredDistanceEReceipt({transaction}: HoveredDistanceEReceiptProps) { | ||
| const styles = useThemeStyles(); | ||
| const [boxWidth, setBoxWidth] = useState(0); | ||
| const [boxHeight, setBoxHeight] = useState(0); | ||
| const [cardHeight, setCardHeight] = useState(0); | ||
|
|
||
| const scale = boxWidth && boxHeight && cardHeight ? Math.min(boxWidth / E_RECEIPT_CARD_WIDTH, boxHeight / cardHeight) : 0; | ||
|
|
||
| const onOverlayLayout = (event: LayoutChangeEvent) => { | ||
| setBoxWidth(event.nativeEvent.layout.width); | ||
| setBoxHeight(event.nativeEvent.layout.height); | ||
| }; | ||
|
|
||
| const onCardLayout = (event: LayoutChangeEvent) => { | ||
| setCardHeight(event.nativeEvent.layout.height); | ||
| }; | ||
|
|
||
| return ( | ||
| <View | ||
| style={[styles.pAbsolute, styles.t0, styles.l0, styles.r0, styles.b0, styles.justifyContentCenter, styles.alignItemsCenter, styles.overflowHidden, styles.eReceiptHoverFill]} | ||
| onLayout={onOverlayLayout} | ||
| pointerEvents="none" | ||
| > | ||
| <View | ||
| style={[{width: E_RECEIPT_CARD_WIDTH}, scale ? {transform: [{scale}]} : styles.opacity0]} | ||
| onLayout={onCardLayout} | ||
| > | ||
| <DistanceEReceipt transaction={transaction} /> | ||
| </View> | ||
| </View> | ||
| ); | ||
| } | ||
|
|
||
| HoveredDistanceEReceipt.displayName = 'HoveredDistanceEReceipt'; | ||
|
WojtekBoman marked this conversation as resolved.
Outdated
|
||
|
|
||
| export default HoveredDistanceEReceipt; | ||
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 |
|---|---|---|
|
|
@@ -57,6 +57,7 @@ import { | |
| import trackExpenseCreationError from '@libs/telemetry/trackExpenseCreationError'; | ||
| import { | ||
| didReceiptScanSucceed as didReceiptScanSucceedTransactionUtils, | ||
| getWaypoints, | ||
| hasEReceipt, | ||
| hasReceiptSource, | ||
| hasReceipt as hasReceiptTransactionUtils, | ||
|
|
@@ -79,6 +80,7 @@ import type * as OnyxTypes from '@src/types/onyx'; | |
| import type {TransactionPendingFieldsKey} from '@src/types/onyx/Transaction'; | ||
| import type {FileObject} from '@src/types/utils/Attachment'; | ||
| import {isEmptyObject} from '@src/types/utils/EmptyObject'; | ||
| import HoveredDistanceEReceipt from './HoveredDistanceEReceipt'; | ||
| import {isElementHovered, resetButtonHoverState} from './receiptHoverUtils'; | ||
| import ReportActionItemImage from './ReportActionItemImage'; | ||
|
|
||
|
|
@@ -171,9 +173,14 @@ function MoneyRequestReceiptView({ | |
| const transactionViolations = useTransactionViolations(transaction?.transactionID); | ||
| const [policyCategories] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${moneyRequestReport?.policyID}`); | ||
|
|
||
| const isDistanceRequest = isDistanceRequestTransactionUtils(transaction); | ||
| const hasReceipt = hasReceiptTransactionUtils(updatedTransaction ?? transaction); | ||
| const isTransactionScanning = isScanning(updatedTransaction ?? transaction); | ||
| const displayedTransaction = updatedTransaction ?? transaction; | ||
| const isDistanceRequest = isDistanceRequestTransactionUtils(displayedTransaction); | ||
| // A merged distance expense can be typed `distance-manual` while still carrying the map waypoints/route from the | ||
|
WojtekBoman marked this conversation as resolved.
|
||
| // expense it was merged with, so fall back to the presence of waypoints to still surface the distance e-receipt. | ||
| const hasDistanceWaypoints = Object.keys(getWaypoints(displayedTransaction) ?? {}).length > 0; | ||
| const isMapDistanceRequest = !!displayedTransaction && isDistanceRequest && (!isManualDistanceRequest(displayedTransaction) || hasDistanceWaypoints); | ||
| const hasReceipt = hasReceiptTransactionUtils(displayedTransaction); | ||
| const isTransactionScanning = isScanning(displayedTransaction); | ||
| const didReceiptScanSucceed = hasReceipt && didReceiptScanSucceedTransactionUtils(transaction); | ||
| const isInvoice = isInvoiceReport(moneyRequestReport); | ||
| const isChatReportArchived = useReportIsArchived(moneyRequestReport?.chatReportID); | ||
|
|
@@ -255,10 +262,9 @@ function MoneyRequestReceiptView({ | |
|
|
||
| let receiptURIs; | ||
| if (hasReceipt) { | ||
| receiptURIs = getThumbnailAndImageURIs(updatedTransaction ?? transaction); | ||
| receiptURIs = getThumbnailAndImageURIs(displayedTransaction); | ||
| } | ||
| const transactionForReceipt = updatedTransaction ?? transaction; | ||
| const isEReceiptTransaction = !!transactionForReceipt && !hasReceiptSource(transactionForReceipt) && hasEReceipt(transactionForReceipt); | ||
| const isEReceiptTransaction = !!displayedTransaction && !hasReceiptSource(displayedTransaction) && hasEReceipt(displayedTransaction); | ||
| const canZoomReceipt = hasReceipt && !isLoading && !isTransactionScanning && !isEReceiptTransaction && !!receiptURIs?.image; | ||
| const pendingAction = transaction?.pendingAction; | ||
| // Need to return undefined when we have pendingAction to avoid the duplicate pending action | ||
|
|
@@ -504,8 +510,6 @@ function MoneyRequestReceiptView({ | |
|
|
||
| const showBorderlessLoading = isLoading && fillSpace; | ||
|
|
||
| const isMapDistanceRequest = !!transaction && isDistanceRequest && !isManualDistanceRequest(transaction); | ||
|
|
||
| const canShowReceiptActions = hasReceipt && !isLoading && isEditable && !isMapDistanceRequest && !mergeTransactionID; | ||
| const receiptPendingAction = isDistanceRequest ? getPendingFieldAction('waypoints') : getPendingFieldAction('receipt'); | ||
| const isReceiptOfflinePending = isOffline && !!receiptPendingAction; | ||
|
|
@@ -623,23 +627,26 @@ function MoneyRequestReceiptView({ | |
| isEnabled={canZoomReceipt} | ||
|
Contributor
Author
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. E-receipts zoom on hover is intended |
||
| hoverContainerRef={receiptContainerRef} | ||
| > | ||
| <ReportActionItemImage | ||
| shouldUseThumbnailImage={!fillSpace} | ||
| shouldUseFullHeight={fillSpace} | ||
| thumbnail={receiptURIs?.thumbnail} | ||
| fileExtension={receiptURIs?.fileExtension} | ||
| isThumbnail={receiptURIs?.isThumbnail} | ||
| image={receiptURIs?.image} | ||
| isLocalFile={receiptURIs?.isLocalFile} | ||
| filename={receiptURIs?.filename} | ||
| transaction={updatedTransaction ?? transaction} | ||
| enablePreviewModal | ||
| readonly={readonly || !canEditReceipt} | ||
| mergeTransactionID={mergeTransactionID} | ||
| report={report} | ||
| onLoad={() => setIsLoading(false)} | ||
| onLoadFailure={() => setIsLoading(false)} | ||
| /> | ||
| <> | ||
| <ReportActionItemImage | ||
| shouldUseThumbnailImage={!fillSpace} | ||
| shouldUseFullHeight={fillSpace} | ||
| thumbnail={receiptURIs?.thumbnail} | ||
| fileExtension={receiptURIs?.fileExtension} | ||
| isThumbnail={receiptURIs?.isThumbnail} | ||
| image={receiptURIs?.image} | ||
| isLocalFile={receiptURIs?.isLocalFile} | ||
| filename={receiptURIs?.filename} | ||
| transaction={updatedTransaction ?? transaction} | ||
| enablePreviewModal | ||
| readonly={readonly || !canEditReceipt} | ||
| mergeTransactionID={mergeTransactionID} | ||
| report={report} | ||
| onLoad={() => setIsLoading(false)} | ||
| onLoadFailure={() => setIsLoading(false)} | ||
| /> | ||
| {isMapDistanceRequest && hovered && !!displayedTransaction && <HoveredDistanceEReceipt transaction={displayedTransaction} />} | ||
| </> | ||
| </ReceiptHoverZoom> | ||
| </View> | ||
| {canShowReceiptActions && ( | ||
|
|
||
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.
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.
Uh oh!
There was an error while loading. Please reload this page.