Skip to content

Commit

Permalink
fix: CC-344 highlighting images when switching albums
Browse files Browse the repository at this point in the history
  • Loading branch information
MikkoKuivanenRS committed Oct 20, 2023
1 parent 955f3fe commit 8098ca1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
9 changes: 5 additions & 4 deletions Source/Pages/Gallery/YPLibraryVC+CollectionView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ extension YPLibraryVC: UICollectionViewDelegate {
cell.durationLabel.isHidden = !isVideo
cell.durationLabel.text = isVideo ? YPHelper.formattedStrigFrom(asset.duration) : ""
cell.multipleSelectionIndicator.isHidden = !isMultipleSelectionEnabled || (isMultipleSelectionEnabled && isVideo)
cell.isSelected = currentlySelectedIndex == indexPath.row
cell.isSelected = !disableAutomaticCellSelection && currentlySelectedIndex == indexPath.row && selectedItems.contains(where: { $0.assetIdentifier == asset.localIdentifier })
cell.isUserInteractionEnabled = !(isMultipleSelectionEnabled && isVideo)

// Set correct selection number
Expand Down Expand Up @@ -187,14 +187,14 @@ extension YPLibraryVC: UICollectionViewDelegate {
let cellIsInTheSelectionPool = isInSelectionPool(indexPath: indexPath)
let cellIsCurrentlySelected = previouslySelectedIndexPath.row == currentlySelectedIndex
if cellIsInTheSelectionPool {
if cellIsCurrentlySelected {
if cellIsCurrentlySelected && !disableAutomaticCellSelection {
deselect(indexPath: indexPath)
}
} else if isLimitExceeded == false {
addToSelection(indexPath: indexPath)
}

if (cellIsCurrentlySelected && !cellIsInTheSelectionPool) || !cellIsCurrentlySelected {
if (cellIsCurrentlySelected && !cellIsInTheSelectionPool) || !cellIsCurrentlySelected || disableAutomaticCellSelection {
disableAutomaticCellSelection = false
collectionView.cellForItem(at: indexPath)?.isSelected = true
}

Expand All @@ -212,6 +212,7 @@ extension YPLibraryVC: UICollectionViewDelegate {
}
collectionView.reloadItems(at: [indexPath, previouslySelectedIndexPath])
}
disableAutomaticCellSelection = false
}

public func collectionView(_ collectionView: UICollectionView, shouldSelectItemAt indexPath: IndexPath) -> Bool {
Expand Down
8 changes: 4 additions & 4 deletions Source/Pages/Gallery/YPLibraryVC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public final class YPLibraryVC: UIViewController, YPPermissionCheckable {
public var currentlySelectedIndex: Int = 0
internal let panGestureHelper = PanGestureHelper()
internal var isInitialized = false
var disableAutomaticCellSelection = false

// MARK: - Init

Expand Down Expand Up @@ -91,6 +92,7 @@ public final class YPLibraryVC: UIViewController, YPPermissionCheckable {
}

func setAlbum(_ album: YPAlbum) {
disableAutomaticCellSelection = isMultipleSelectionEnabled
if YPConfig.showsLibraryButtonInTitle {
title = album.title
} else {
Expand Down Expand Up @@ -252,12 +254,10 @@ public final class YPLibraryVC: UIViewController, YPPermissionCheckable {
}

if mediaManager.hasResultItems,
let firstAsset = mediaManager.getAsset(at: 0) {
let firstAsset = mediaManager.getAsset(with: selectedItems.last?.assetIdentifier) ?? mediaManager.getAsset(at: 0) {
changeAsset(firstAsset)
v.collectionView.reloadData()
v.collectionView.selectItem(at: IndexPath(row: 0, section: 0),
animated: false,
scrollPosition: UICollectionView.ScrollPosition())

if !isMultipleSelectionEnabled && YPConfig.library.preSelectItemOnMultipleSelection {
addToSelection(indexPath: IndexPath(row: 0, section: 0))
}
Expand Down

0 comments on commit 8098ca1

Please sign in to comment.