diff --git a/src/components/MediaViewer/MediaViewer.js b/src/components/MediaViewer/MediaViewer.js index 4a53bfc8b..cf50d35ad 100644 --- a/src/components/MediaViewer/MediaViewer.js +++ b/src/components/MediaViewer/MediaViewer.js @@ -83,8 +83,13 @@ const MediaViewer = ( { // If we've removed an item the selectedPhoto index might refer to a item // that no longer exists, so change it to the previous one useEffect( ( ) => { - if ( selectedMediaIndex >= uris.length ) { - setSelectedMediaIndex( Math.max( 0, selectedMediaIndex - 1 ) ); + if ( uris.length > 0 && selectedMediaIndex >= uris.length ) { + const newIndex = Math.max( 0, selectedMediaIndex - 1 ); + setSelectedMediaIndex( newIndex ); + horizontalScroll?.current?.scrollToIndex( { + index: newIndex, + animated: true + } ); } }, [selectedMediaIndex, setSelectedMediaIndex, uris.length] );