Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions src/components/ReportActionItem/HoveredDistanceEReceipt.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
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;
};

/**
* Overlay that shows the full distance e-receipt on hover scaled down (object-fit: contain) to sit inside the
* fixed-size receipt box without changing the box dimensions. The space around the portrait card is filled with
* the card's own background color so there is no white gap.
*/
Comment thread
WojtekBoman marked this conversation as resolved.
Outdated
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}
>
Comment thread
WojtekBoman marked this conversation as resolved.
<View
style={[{width: E_RECEIPT_CARD_WIDTH}, scale ? {transform: [{scale}]} : styles.opacity0]}
onLayout={onCardLayout}
>
<DistanceEReceipt transaction={transaction} />
</View>
</View>
);
}

HoveredDistanceEReceipt.displayName = 'HoveredDistanceEReceipt';
Comment thread
WojtekBoman marked this conversation as resolved.
Outdated

export default HoveredDistanceEReceipt;
43 changes: 24 additions & 19 deletions src/components/ReportActionItem/MoneyRequestReceiptView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,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';

Expand Down Expand Up @@ -172,6 +173,7 @@ function MoneyRequestReceiptView({
const [policyCategories] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${moneyRequestReport?.policyID}`);

const isDistanceRequest = isDistanceRequestTransactionUtils(transaction);
const isMapDistanceRequest = !!transaction && isDistanceRequest && !isManualDistanceRequest(transaction);

@QichenZhu QichenZhu Jun 4, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment is genuine.

Steps to reproduce:

  1. Create a map distance expense.
  2. Create a manual distance expense.
  3. Merge the 2nd expense into the 1st expense and select the 1st expense as the merchant to keep.

Expected result:

E-receipt displays on hover.

Actual result:

Only the map enlarges on hover.

Screen.Recording.2026-06-04.at.10.55.21.PM.mov

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now it should work fine, I've added here logic checking if the transaction has defined waypoints, if so, we'll display an e-receipt

const hasReceipt = hasReceiptTransactionUtils(updatedTransaction ?? transaction);
const isTransactionScanning = isScanning(updatedTransaction ?? transaction);
const didReceiptScanSucceed = hasReceipt && didReceiptScanSucceedTransactionUtils(transaction);
Expand Down Expand Up @@ -504,8 +506,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;
Expand Down Expand Up @@ -623,23 +623,28 @@ function MoneyRequestReceiptView({
isEnabled={canZoomReceipt}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The 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)}
/>
{/* On hover, a map distance receipt overlays the full e-receipt (map + amount + waypoints), scaled to fit the
box without resizing it, matching Expensify Classic. The map underneath keeps the box at its resting size. */}
Comment thread
WojtekBoman marked this conversation as resolved.
Outdated
{isMapDistanceRequest && hovered && !!transactionForReceipt && <HoveredDistanceEReceipt transaction={transactionForReceipt} />}
Comment thread
WojtekBoman marked this conversation as resolved.
Outdated
</>
</ReceiptHoverZoom>
</View>
{canShowReceiptActions && (
Expand Down
4 changes: 4 additions & 0 deletions src/styles/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4225,6 +4225,10 @@ const staticStyles = (theme: ThemeColors) =>
overflow: 'hidden',
},

eReceiptHoverFill: {
backgroundColor: colors.green800,
},

eReceiptBackgroundThumbnail: {
...sizing.w100,
position: 'absolute',
Expand Down
Loading