Fixes crash loading save states on iOS 17
Crashes due to GridCollectionViewLayout returning outdated cached layout information when inserting “Auto” save states section for the first time. To fix this, we now clear the layout cache in invalidateLayout(with:) when relevant.
This commit is contained in:
parent
21147969ea
commit
3e858c652f
@ -66,6 +66,18 @@ class GridCollectionViewLayout: UICollectionViewFlowLayout
|
||||
self.sectionInset.right = self.interitemSpacing + self.contentInset.right
|
||||
}
|
||||
|
||||
override func invalidateLayout(with context: UICollectionViewLayoutInvalidationContext)
|
||||
{
|
||||
super.invalidateLayout(with: context)
|
||||
|
||||
if let context = context as? UICollectionViewFlowLayoutInvalidationContext,
|
||||
context.invalidateFlowLayoutAttributes || context.invalidateFlowLayoutDelegateMetrics || context.invalidateEverything
|
||||
{
|
||||
// We must clear layout cache on iOS 17 or later to prevent crashing due to returning outdated layout attributes.
|
||||
self.cachedLayoutAttributes = [:]
|
||||
}
|
||||
}
|
||||
|
||||
override func layoutAttributesForElements(in rect: CGRect) -> [UICollectionViewLayoutAttributes]?
|
||||
{
|
||||
let layoutAttributes = super.layoutAttributesForElements(in: rect)?.map({ $0.copy() }) as! [UICollectionViewLayoutAttributes]
|
||||
|
||||
Loading…
Reference in New Issue
Block a user