Skip to content

Commit 4ec5f12

Browse files
authored
Merge pull request #72856 from dukenv0307/fix/72444
Fix: violations under a receipt on the one expense report view not showing sometimes
2 parents 127f8cc + c6be50d commit 4ec5f12

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

src/components/ReceiptImage/index.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,9 @@ type ReceiptImageProps = (
123123

124124
/** Callback to be called when the image loads */
125125
onLoad?: (event?: {nativeEvent: {width: number; height: number}}) => void;
126+
127+
/** Callback to be called when the image fails to load */
128+
onLoadFailure?: () => void;
126129
};
127130

128131
function ReceiptImage({
@@ -150,6 +153,7 @@ function ReceiptImage({
150153
loadingIndicatorStyles,
151154
thumbnailContainerStyles,
152155
onLoad,
156+
onLoadFailure,
153157
}: ReceiptImageProps) {
154158
const styles = useThemeStyles();
155159
const [receiptImageWidth, setReceiptImageWidth] = useState<number | undefined>(undefined);
@@ -217,6 +221,7 @@ function ReceiptImage({
217221
fallbackIconBackground={fallbackIconBackground}
218222
objectPosition={shouldUseInitialObjectPosition ? CONST.IMAGE_OBJECT_POSITION.INITIAL : CONST.IMAGE_OBJECT_POSITION.TOP}
219223
onLoad={onLoad}
224+
onLoadFailure={onLoadFailure}
220225
/>
221226
);
222227
}
@@ -239,6 +244,7 @@ function ReceiptImage({
239244
onLoad={onLoad}
240245
shouldCalculateAspectRatioForWideImage={shouldUseFullHeight}
241246
imageWidthToCalculateHeight={receiptImageWidth}
247+
onError={onLoadFailure}
242248
/>
243249
);
244250
}

src/components/ReportActionItem/MoneyRequestReceiptView.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,10 +343,13 @@ function MoneyRequestReceiptView({
343343
mergeTransactionID={mergeTransactionID}
344344
report={report}
345345
onLoad={() => setIsLoading(false)}
346+
onLoadFailure={() => setIsLoading(false)}
346347
/>
347348
</View>
348349
)}
349-
{!!shouldShowAuditMessage && hasReceipt && !isLoading && receiptAuditMessagesRow}
350+
{/* For WideRHP (fillSpace is true), we need to wait for the image to load to get the correct size, then display the violation message to avoid the jumping issue.
351+
Otherwise (when fillSpace is false), we use a fixed size, so there's no need to wait for the image to load. */}
352+
{!!shouldShowAuditMessage && hasReceipt && (!isLoading || !fillSpace) && receiptAuditMessagesRow}
350353
</OfflineWithFeedback>
351354
)}
352355
{!shouldShowReceiptEmptyState && !hasReceipt && <View style={{marginVertical: 6}} />}

src/components/ReportActionItem/ReportActionItemImage.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ type ReportActionItemImageProps = {
7878

7979
/** Callback to be called when the image loads */
8080
onLoad?: (event?: {nativeEvent: {width: number; height: number}}) => void;
81+
82+
/** Callback to be called when the image fails to load */
83+
onLoadFailure?: () => void;
8184
};
8285

8386
/**
@@ -106,6 +109,7 @@ function ReportActionItemImage({
106109
report: reportProp,
107110
shouldUseThumbnailImage,
108111
onLoad,
112+
onLoadFailure,
109113
}: ReportActionItemImageProps) {
110114
const styles = useThemeStyles();
111115
const {translate} = useLocalize();
@@ -195,6 +199,7 @@ function ReportActionItemImage({
195199
{...propsObj}
196200
onLoad={onLoad}
197201
shouldUseFullHeight={shouldUseFullHeight}
202+
onLoadFailure={onLoadFailure}
198203
/>
199204
</PressableWithoutFocus>
200205
)}
@@ -208,6 +213,7 @@ function ReportActionItemImage({
208213
shouldUseFullHeight={shouldUseFullHeight}
209214
thumbnailContainerStyles={styles.thumbnailImageContainerHover}
210215
onLoad={onLoad}
216+
onLoadFailure={onLoadFailure}
211217
/>
212218
);
213219
}

0 commit comments

Comments
 (0)