diff --git a/src/components/Attachments/AttachmentCarousel/index.js b/src/components/Attachments/AttachmentCarousel/index.js index 99a23835fd97..ad907707b9a7 100644 --- a/src/components/Attachments/AttachmentCarousel/index.js +++ b/src/components/Attachments/AttachmentCarousel/index.js @@ -37,17 +37,18 @@ function AttachmentCarousel({report, reportActions, source, onNavigate, setDownl const [attachments, setAttachments] = useState([]); const [activeSource, setActiveSource] = useState(source); const [shouldShowArrows, setShouldShowArrows, autoHideArrows, cancelAutoHideArrows] = useCarouselArrows(); + const [isReceipt, setIsReceipt] = useState(false); const compareImage = useCallback( (attachment) => { - if (attachment.isReceipt) { + if (attachment.isReceipt && isReceipt) { const action = ReportActionsUtils.getParentReportAction(report); const transactionID = _.get(action, ['originalMessage', 'IOUTransactionID']); return attachment.transactionID === transactionID; } return attachment.source === source; }, - [source, report], + [source, report, isReceipt], ); useEffect(() => { @@ -86,10 +87,12 @@ function AttachmentCarousel({report, reportActions, source, onNavigate, setDownl // to get the index of the current page const entry = _.first(viewableItems); if (!entry) { + setIsReceipt(false); setActiveSource(null); return; } + setIsReceipt(entry.item.isReceipt); setPage(entry.index); setActiveSource(entry.item.source); diff --git a/src/components/Attachments/AttachmentCarousel/index.native.js b/src/components/Attachments/AttachmentCarousel/index.native.js index 8c6957c9371a..7088a5c7057c 100644 --- a/src/components/Attachments/AttachmentCarousel/index.native.js +++ b/src/components/Attachments/AttachmentCarousel/index.native.js @@ -27,17 +27,18 @@ function AttachmentCarousel({report, reportActions, source, onNavigate, onClose, const [activeSource, setActiveSource] = useState(source); const [isPinchGestureRunning, setIsPinchGestureRunning] = useState(true); const [shouldShowArrows, setShouldShowArrows, autoHideArrows, cancelAutoHideArrows] = useCarouselArrows(); + const [isReceipt, setIsReceipt] = useState(false); const compareImage = useCallback( (attachment) => { - if (attachment.isReceipt) { + if (attachment.isReceipt && isReceipt) { const action = ReportActionsUtils.getParentReportAction(report); const transactionID = _.get(action, ['originalMessage', 'IOUTransactionID']); return attachment.transactionID === transactionID; } return attachment.source === source; }, - [source, report], + [source, report, isReceipt], ); useEffect(() => { @@ -76,6 +77,7 @@ function AttachmentCarousel({report, reportActions, source, onNavigate, onClose, const item = attachments[newPageIndex]; setPage(newPageIndex); + setIsReceipt(item.isReceipt); setActiveSource(item.source); onNavigate(item);