Change how profile header collection view cell is sized

Fixes crash due to collection view layout loop in some circumstances

Closes #537
This commit is contained in:
Shadowfacts 2024-08-31 10:49:21 -04:00
parent 59af29ff64
commit cc696e58fc
1 changed files with 12 additions and 5 deletions

View File

@ -63,11 +63,18 @@ class ProfileHeaderCollectionViewCell: UICollectionViewCell {
} }
} }
// overrides an internal method override func preferredLayoutAttributesFitting(_ layoutAttributes: UICollectionViewLayoutAttributes) -> UICollectionViewLayoutAttributes {
// when the super impl is used, preferredLayoutAttributesFitting(_:) isn't called while the view is offscreen (i.e., window == nil) switch state {
// and so the collection view imposes a height of 44pts which breaks the layout case .unloaded:
@objc func _preferredLayoutAttributesFittingAttributes(_ attributes: UICollectionViewLayoutAttributes) -> UICollectionViewLayoutAttributes { return super.preferredLayoutAttributesFitting(layoutAttributes)
return preferredLayoutAttributesFitting(attributes) case .placeholder(let heightConstraint):
layoutAttributes.size.height = heightConstraint.constant
return layoutAttributes
case .view(let profileHeaderView):
let size = profileHeaderView.systemLayoutSizeFitting(layoutAttributes.size, withHorizontalFittingPriority: .required, verticalFittingPriority: .fittingSizeLevel)
layoutAttributes.size = size
return layoutAttributes
}
} }
enum State { enum State {