Skip to content

Commit

Permalink
fix native
Browse files Browse the repository at this point in the history
  • Loading branch information
tienifr committed Sep 14, 2023
1 parent 0f15346 commit 189975d
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/components/Attachments/AttachmentCarousel/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import * as Illustrations from '../../Icon/Illustrations';
import variables from '../../../styles/variables';
import compose from '../../../libs/compose';
import withLocalize from '../../withLocalize';
import * as ReportActionsUtils from '../../../libs/ReportActionsUtils';

function AttachmentCarousel({report, reportActions, source, onNavigate, onClose, setDownloadButtonVisibility, translate}) {
const pagerRef = useRef(null);
Expand All @@ -27,13 +28,25 @@ function AttachmentCarousel({report, reportActions, source, onNavigate, onClose,
const [isPinchGestureRunning, setIsPinchGestureRunning] = useState(true);
const [shouldShowArrows, setShouldShowArrows, autoHideArrows, cancelAutoHideArrows] = useCarouselArrows();

const compareImage = useCallback(
(attachment) => {
if (attachment.isReceipt) {
const action = ReportActionsUtils.getParentReportAction(report);
const transactionID = _.get(action, ['originalMessage', 'IOUTransactionID']);
return attachment.transactionID === transactionID;
}
return attachment.source === source;
},
[source, report],
);

useEffect(() => {
const attachmentsFromReport = extractAttachmentsFromReport(report, reportActions);

const initialPage = _.findIndex(attachmentsFromReport, (a) => a.source === source);
const initialPage = _.findIndex(attachmentsFromReport, compareImage);

// Dismiss the modal when deleting an attachment during its display in preview.
if (initialPage === -1 && _.find(attachments, (a) => a.source === source)) {
if (initialPage === -1 && _.find(attachments, compareImage)) {
Navigation.dismissModal();
} else {
setPage(initialPage);
Expand All @@ -46,7 +59,7 @@ function AttachmentCarousel({report, reportActions, source, onNavigate, onClose,
if (!_.isUndefined(attachmentsFromReport[initialPage])) onNavigate(attachmentsFromReport[initialPage]);
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [report, reportActions, source]);
}, [reportActions, compareImage]);

/**
* Updates the page state when the user navigates between attachments
Expand Down

0 comments on commit 189975d

Please sign in to comment.