I have some code which currently assumes that UICollectionViewDelegate
- collectionView(_: UICollectionView, willDisplay _: UICollectionViewCell, forItemAt indexPath: IndexPath)
will be called as the user scrolls through the collection view and cells are about to be displayed on-screen.
However on refactoring this screen to use the UICollectionViewDiffableDataSource
APIs I noticed that willDisplay
is called for every indexPath in the collection view's data as a result of calling UICollectionViewDiffableDataSource
apply`.
This is reproducible in Apple's sample app Updating Collection Views Using Diffable Data Sources running on iOS 15.
Is this behaviour intentional?
Is there another reliable way to be informed of when a cell is about to be displayed as the user is scrolling through the collection view?
As a workaround I am using a boolean flag to indicate when the data source is updating and setting that to false in the completion of UICollectionViewDiffableDataSource
apply
.
Many thanks!