Repository navigation
feat: show full distance e-receipt on hover for map distance requests v2 #93102
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 5 commits into
Expensify:main
from
software-mansion-labs:feat/zoom-map-e-receipts-v2
Jun 15, 2026
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
635242f
feat: show full distance e-receipt on hover for map distance requests
WojtekBoman 58a1b07
fix: don't show distance e-receipt overlay on odometer receipts (#93001)
WojtekBoman 541cd6a
fix: keep distance e-receipt overlay visible while hovering during zo…
WojtekBoman 673cb40
fix: hide distance e-receipt overlay while receipt is regenerating (#…
WojtekBoman 9b14e98
docs: clarify why hovered state is re-synced on mouse move over the r…
WojtekBoman 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
47 changes: 47 additions & 0 deletions
47
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,47 @@ | ||
| 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'; | ||
|
|
||
| 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 / variables.eReceiptHoverCardWidth, 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: variables.eReceiptHoverCardWidth}, scale ? {transform: [{scale}]} : styles.opacity0]} | ||
| onLayout={onCardLayout} | ||
| > | ||
| <DistanceEReceipt transaction={transaction} /> | ||
| </View> | ||
| </View> | ||
| ); | ||
| } | ||
|
|
||
| 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
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 |
|---|---|---|
|
|
@@ -178,6 +178,20 @@ function isOdometerDistanceRequest(transaction: OnyxEntry<Transaction>): boolean | |
| return transaction?.iouRequestType === CONST.IOU.REQUEST_TYPE.DISTANCE_ODOMETER; | ||
| } | ||
|
|
||
| /** | ||
| * Whether a distance expense's receipt is a map/route receipt (as opposed to an odometer photo or a | ||
| * pure manual entry that has no route). Used to decide whether the full distance e-receipt (map + | ||
| * amount + waypoints) should be shown. A merged distance expense can be typed `distance-manual` yet | ||
| * still carry waypoints, so the presence of waypoints keeps those included. | ||
| */ | ||
| function isMapBasedDistanceRequest(transaction: OnyxEntry<Transaction>): boolean { | ||
| if (!isDistanceRequest(transaction) || isOdometerDistanceRequest(transaction)) { | ||
| return false; | ||
| } | ||
| const hasWaypoints = Object.keys(getWaypoints(transaction) ?? {}).length > 0; | ||
| return isMapDistanceRequest(transaction) || isGPSDistanceRequest(transaction) || hasWaypoints; | ||
| } | ||
|
|
||
| function isScanRequest(transaction: OnyxEntry<Pick<Transaction, 'iouRequestType'>>): boolean { | ||
| return transaction?.iouRequestType === CONST.IOU.REQUEST_TYPE.SCAN; | ||
| } | ||
|
|
@@ -1058,6 +1072,24 @@ function isFetchingWaypointsFromServer(transaction: OnyxInputOrEntry<Transaction | |
| return !!transaction?.pendingFields?.waypoints; | ||
| } | ||
|
|
||
| // Editing any of these fields makes the server regenerate the distance map receipt. `customUnitRateID`/`distance` | ||
| // aren't typed `pendingFields` keys (they live on the comment), so this is matched by name rather than property access. | ||
| const DISTANCE_RECEIPT_REGENERATION_FIELDS = new Set(['waypoints', 'distance', 'merchant', 'customUnitRateID']); | ||
|
|
||
| /** | ||
| * After a distance/rate/waypoint edit the server regenerates the map receipt and invalidates the prior URL, but the | ||
| * local `receipt.source` only refreshes once the Pusher push arrives. While any of these edits are pending the stored | ||
| * map image is stale and can't be regenerated locally. | ||
| */ | ||
| function hasPendingDistanceReceiptRegeneration(transaction: OnyxInputOrEntry<Transaction>): boolean { | ||
|
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. Can you add unit test for this? |
||
| const pendingFields = transaction?.pendingFields; | ||
| if (!pendingFields) { | ||
| return false; | ||
| } | ||
| const hasPendingRegenerationField = Object.entries(pendingFields).some(([field, pendingAction]) => !!pendingAction && DISTANCE_RECEIPT_REGENERATION_FIELDS.has(field)); | ||
| return hasPendingRegenerationField; | ||
| } | ||
|
|
||
| /** | ||
| * Return the merchant field from the transaction, return the modifiedMerchant if present. | ||
| */ | ||
|
|
@@ -2947,11 +2979,13 @@ export { | |
| haveWaypointAddressesChanged, | ||
| isDistanceRequest, | ||
| isMapDistanceRequest, | ||
| isMapBasedDistanceRequest, | ||
| isGPSDistanceRequest, | ||
| isManualDistanceRequest, | ||
| isOdometerDistanceRequest, | ||
| isDistanceExpenseType, | ||
| isFetchingWaypointsFromServer, | ||
| hasPendingDistanceReceiptRegeneration, | ||
| isExpensifyCardTransaction, | ||
| isManagedCardTransaction, | ||
| isDuplicate, | ||
|
|
||
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
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.
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.
Hey, should we rewrite
HoveredDistanceEReceiptto use Reanimated? The scale calculation could move off the JS thread withuseSharedValue+useAnimatedStyle, avoiding re-renders on layout changes. Is there a plan to use this on mobile too? That would make it more worth it.Uh oh!
There was an error while loading. Please reload this page.
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.
I think we can keep it as-is for now — the scale isn't animated, it's computed once from the initial layout, so there isn't really any per-frame work to move off the JS thread. The component is also hover-only, so it won't be used on mobile for now. If we ever build a mobile preview for it, Reanimated would definitely be worth revisiting 🫡