From 736fc0ffe7459ce105344a4535db9531d0fae42c Mon Sep 17 00:00:00 2001 From: Ronit Maitra <29394217+RonitOfficial@users.noreply.github.com> Date: Tue, 1 Oct 2024 16:23:40 +0530 Subject: [PATCH] Single media in single album deselect crash fix --- Source/Pages/Gallery/YPLibraryVC+CollectionView.swift | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Source/Pages/Gallery/YPLibraryVC+CollectionView.swift b/Source/Pages/Gallery/YPLibraryVC+CollectionView.swift index a13ffeb3f..37e401f32 100644 --- a/Source/Pages/Gallery/YPLibraryVC+CollectionView.swift +++ b/Source/Pages/Gallery/YPLibraryVC+CollectionView.swift @@ -68,8 +68,12 @@ extension YPLibraryVC { // Replace the current selected image with the previously selected one if let previouslySelectedIndexPath = selectedIndexPaths.last { - v.collectionView.deselectItem(at: indexPath, animated: false) - v.collectionView.selectItem(at: previouslySelectedIndexPath, animated: false, scrollPosition: []) + if(v.collectionView.indexPathsForSelectedItems?.contains(indexPath) ?? false){ + v.collectionView.deselectItem(at: indexPath, animated: false) + } + if(v.collectionView.indexPathsForVisibleItems.contains(previouslySelectedIndexPath)){ + v.collectionView.selectItem(at: previouslySelectedIndexPath, animated: false, scrollPosition: []) + } currentlySelectedIndex = previouslySelectedIndexPath.row changeAsset(mediaManager.getAsset(at: previouslySelectedIndexPath.row)) }