diff --git a/Tusker/Screens/Profile/ProfileHeaderCollectionViewCell.swift b/Tusker/Screens/Profile/ProfileHeaderCollectionViewCell.swift index e74141b6..abf36ddc 100644 --- a/Tusker/Screens/Profile/ProfileHeaderCollectionViewCell.swift +++ b/Tusker/Screens/Profile/ProfileHeaderCollectionViewCell.swift @@ -63,11 +63,18 @@ class ProfileHeaderCollectionViewCell: UICollectionViewCell { } } - // overrides an internal method - // when the super impl is used, preferredLayoutAttributesFitting(_:) isn't called while the view is offscreen (i.e., window == nil) - // and so the collection view imposes a height of 44pts which breaks the layout - @objc func _preferredLayoutAttributesFittingAttributes(_ attributes: UICollectionViewLayoutAttributes) -> UICollectionViewLayoutAttributes { - return preferredLayoutAttributesFitting(attributes) + override func preferredLayoutAttributesFitting(_ layoutAttributes: UICollectionViewLayoutAttributes) -> UICollectionViewLayoutAttributes { + switch state { + case .unloaded: + return super.preferredLayoutAttributesFitting(layoutAttributes) + 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 {