diff --git a/src/components/AttachmentCarousel/createInitialState.js b/src/components/AttachmentCarousel/createInitialState.js index 770b5f243eee..d4c64843c8c9 100644 --- a/src/components/AttachmentCarousel/createInitialState.js +++ b/src/components/AttachmentCarousel/createInitialState.js @@ -3,6 +3,7 @@ import {Parser as HtmlParser} from 'htmlparser2'; import * as DeviceCapabilities from '../../libs/DeviceCapabilities'; import * as ReportActionsUtils from '../../libs/ReportActionsUtils'; import tryResolveUrlFromApiRoot from '../../libs/tryResolveUrlFromApiRoot'; +import Navigation from '../../libs/Navigation/Navigation'; import CONST from '../../CONST'; /** @@ -50,7 +51,7 @@ function createInitialState(props) { const page = _.findIndex(attachments, (a) => a.source === props.source); if (page === -1) { - throw new Error('Attachment not found'); + Navigation.dismissModal(); } // Update the parent modal's state with the source and name from the mapped attachments diff --git a/src/components/AttachmentCarousel/index.js b/src/components/AttachmentCarousel/index.js index b5637cc53568..6e99abaea61a 100644 --- a/src/components/AttachmentCarousel/index.js +++ b/src/components/AttachmentCarousel/index.js @@ -53,7 +53,15 @@ function AttachmentCarousel(props) { setPage(initialState.page); setAttachments(initialState.attachments); // eslint-disable-next-line react-hooks/exhaustive-deps - }, []); + }, [props.reportActions]); + + useEffect(() => { + if (!scrollRef || !scrollRef.current) { + return; + } + scrollRef.current.scrollToIndex({index: page, animated: false}); + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [attachments]); /** * Calculate items layout information to optimize scrolling performance