IBPCollectionViewCompositionalLayout
IBPCollectionViewCompositionalLayout copied to clipboard
Reload 2 items toggle state in same section causing the whole section to reload( below iOS 13 )
Reloading "state only values of specific items in horizontal section" is causing the section to scrollto first (it's reloading whole section)
///on cell did select
guard var currentSnapshot = dataSource?.snapshot() else { return }
var itemsToReload:[SomeClassTypeHashable] = []
//toggle state of current cell
let selectedItem = currentSnapshot.sectionIdentifiers[indexPath.section].items[indexPath.item]
if var item = selectedItem as? Playable{
item.isPlaying = !item.isPlaying
itemsToReload.append(selectedItem)
}
//reset state of all other cells as playing capabilities will only be available at one cell at a time.
currentSnapshot.sectionIdentifiers[indexPath.section].items.filter({(($0 as? Playable)?.isPlaying ?? false) == true && $0 != selectedItem}).forEach({
var prevItem = ($0 as! Playable)
prevItem.isPlaying = false
itemsToReload.append(castedPrevItem as! SomeClassTypeHashable)
})
currentSnapshot.reloadItems(itemsToReload)
dataSource?.apply(currentSnapshot)
Works perfectly in iOS 13 but scrolling issues are prominent in below versions of iOS 13.