Collection reusable view should call super.prepareForReuse().
The UICollectionViewLayout preferred layout attributes mechanism apparently holds internal states inside the cells/reusable views, which needs to be reset by super.prepareForReuse() before the cell is reused.
Since ASCollectionViewCell does not call super.prepareForResue(), those states are not being reset. This causes UIKit to consider a reused cell bound to a new index path has already been measured for preferred attributes, when it goes on screen. Therefore, reused cells are often stuck at the estimated size, where the whole preferred layout attributes lifecycle stops happening at all, while supposedly it should have been triggered every time the item goes on screen.
In order words, this causes issues with both UICollectionViewCompositionalLayout, UICollectionViewFlowLayout, and any custom layout that relies on preferred layout attributes on content self-sizing. Tested on both iOS 13.4 and 14.5.
UITableView cells should call super.prepareForReuse().
Collection reusable view should call
super.prepareForReuse()
.The UICollectionViewLayout preferred layout attributes mechanism apparently holds internal states inside the cells/reusable views, which needs to be reset by
super.prepareForReuse()
before the cell is reused.Since
ASCollectionViewCell
does not callsuper.prepareForResue()
, those states are not being reset. This causes UIKit to consider a reused cell bound to a new index path has already been measured for preferred attributes, when it goes on screen. Therefore, reused cells are often stuck at the estimated size, where the whole preferred layout attributes lifecycle stops happening at all, while supposedly it should have been triggered every time the item goes on screen.In order words, this causes issues with both
UICollectionViewCompositionalLayout
,UICollectionViewFlowLayout
, and any custom layout that relies on preferred layout attributes on content self-sizing. Tested on both iOS 13.4 and 14.5.UITableView cells should call
super.prepareForReuse()
.