Repository navigation
feat: render high-res PDF overlay on receipt hover zoom #93583
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 2 commits into
Expensify:main
from
software-mansion-labs:fix/improve-pdf-receipt-zoom-quality
Jun 17, 2026
Merged
Changes from all commits
Commits
Show all changes
2 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
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
12 changes: 12 additions & 0 deletions
12
src/components/ReportActionItem/ReceiptPDFOverlay/index.native.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,12 @@ | ||
| import type ReceiptPDFOverlayProps from './types'; | ||
|
|
||
| /** | ||
| * Hover-zoom is a web-only interaction, so on native there is no high-resolution PDF overlay to render. | ||
| * Callers only mount this component when hover is supported, so this fallback should never actually render. | ||
| */ | ||
| // eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
| function ReceiptPDFOverlay(props: ReceiptPDFOverlayProps) { | ||
| return null; | ||
| } | ||
|
|
||
| export default ReceiptPDFOverlay; |
87 changes: 87 additions & 0 deletions
87
src/components/ReportActionItem/ReceiptPDFOverlay/index.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,87 @@ | ||
| import React, {useEffect, useState} from 'react'; | ||
| import {PDFPreviewer} from 'react-fast-pdf'; | ||
| import {View} from 'react-native'; | ||
| import useOnyx from '@hooks/useOnyx'; | ||
| import useThemeStyles from '@hooks/useThemeStyles'; | ||
| import addEncryptedAuthTokenToURL from '@libs/addEncryptedAuthTokenToURL'; | ||
| import variables from '@styles/variables'; | ||
| import {retrieveMaxCanvasArea, retrieveMaxCanvasHeight, retrieveMaxCanvasWidth} from '@userActions/CanvasSize'; | ||
| import CONST from '@src/CONST'; | ||
| import ONYXKEYS from '@src/ONYXKEYS'; | ||
| import type ReceiptPDFOverlayProps from './types'; | ||
|
|
||
| const oversamplePercent = `${CONST.RECEIPT.HOVER_ZOOM_SCALE * 100}%`; | ||
| const oversampleContainerStyle = { | ||
| position: 'absolute' as const, | ||
| top: 0, | ||
| left: 0, | ||
| width: oversamplePercent, | ||
| height: oversamplePercent, | ||
| transform: `scale(${1 / CONST.RECEIPT.HOVER_ZOOM_SCALE})`, | ||
| transformOrigin: 'top left', | ||
| }; | ||
|
|
||
| function ReceiptPDFOverlay({sourceURL, isAuthTokenRequired = true, onLoadFailure}: ReceiptPDFOverlayProps) { | ||
| const styles = useThemeStyles(); | ||
| const [session] = useOnyx(ONYXKEYS.SESSION); | ||
| const [maxCanvasArea] = useOnyx(ONYXKEYS.MAX_CANVAS_AREA); | ||
| const [maxCanvasHeight] = useOnyx(ONYXKEYS.MAX_CANVAS_HEIGHT); | ||
| const [maxCanvasWidth] = useOnyx(ONYXKEYS.MAX_CANVAS_WIDTH); | ||
|
|
||
| useEffect(() => { | ||
| // Verify the per-browser canvas limits have been calculated, mirroring PDFView. | ||
| if (!maxCanvasArea) { | ||
| retrieveMaxCanvasArea(); | ||
| } | ||
| if (!maxCanvasHeight) { | ||
| retrieveMaxCanvasHeight(); | ||
| } | ||
| if (!maxCanvasWidth) { | ||
| retrieveMaxCanvasWidth(); | ||
| } | ||
| // eslint-disable-next-line react-hooks/exhaustive-deps -- Run once on mount; canvas limits are one-time browser measurements that don't change | ||
| }, []); | ||
|
|
||
| const fileURL = isAuthTokenRequired ? addEncryptedAuthTokenToURL(sourceURL, session?.encryptedAuthToken ?? '') : sourceURL; | ||
|
|
||
| // Track which URL failed so hasFailed resets automatically when fileURL changes (e.g. after auth token refresh), | ||
| // mirroring the pattern in ThumbnailImage. No useEffect needed — the comparison runs synchronously during render. | ||
| const [failedURL, setFailedURL] = useState<string | null>(null); | ||
| const hasFailed = failedURL !== null && failedURL === fileURL; | ||
|
|
||
| // If the PDF can't be rendered, fall back to the thumbnail underneath by rendering nothing. | ||
| if (hasFailed) { | ||
| return null; | ||
|
WojtekBoman marked this conversation as resolved.
Resolved
|
||
| } | ||
|
|
||
| return ( | ||
| <View | ||
| style={[styles.w100, styles.h100, styles.overflowHidden]} | ||
| pointerEvents="none" | ||
| > | ||
| {/* <div> is required here because `transformOrigin` is a CSS-only property unsupported by React Native's | ||
| View. The oversample-then-scale technique relies on it to anchor the downscale to the top-left corner. */} | ||
| <div style={oversampleContainerStyle}> | ||
|
WojtekBoman marked this conversation as resolved.
Resolved
|
||
| <PDFPreviewer | ||
| file={fileURL} | ||
| pageMaxWidth={variables.pdfPageMaxWidth} | ||
| // Fit the page to the full width of the (oversized) container, matching the thumbnail framing. | ||
| isSmallScreen | ||
| maxCanvasWidth={maxCanvasWidth} | ||
| maxCanvasHeight={maxCanvasHeight} | ||
| maxCanvasArea={maxCanvasArea} | ||
| containerStyle={styles.bgTransparent} | ||
| contentContainerStyle={styles.bgTransparent} | ||
| shouldShowErrorComponent={false} | ||
| LoadingComponent={null} | ||
| onLoadError={() => { | ||
| setFailedURL(fileURL); | ||
| onLoadFailure?.(); | ||
| }} | ||
| /> | ||
| </div> | ||
| </View> | ||
| ); | ||
| } | ||
|
|
||
| export default ReceiptPDFOverlay; | ||
12 changes: 12 additions & 0 deletions
12
src/components/ReportActionItem/ReceiptPDFOverlay/types.ts
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,12 @@ | ||
| type ReceiptPDFOverlayProps = { | ||
| /** Resolved URL of the source PDF. The encrypted auth token is appended internally when required. */ | ||
| sourceURL: string; | ||
|
|
||
| /** Whether the source requires an encrypted auth token */ | ||
| isAuthTokenRequired?: boolean; | ||
|
|
||
| /** Called when the PDF fails to load so the caller can fall back to the thumbnail */ | ||
| onLoadFailure?: () => void; | ||
| }; | ||
|
|
||
| export default ReceiptPDFOverlayProps; |
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.
Uh oh!
There was an error while loading. Please reload this page.