Fix infinite layout loops on timeline (#6942)

* Remove `forceZeroSageAreaInsets` from `VectorHostingController`

* Fix layout issues when adding hosting views into the content view

* Use the new api when adding views into the content

* Add changelog
This commit is contained in:
ismailgulek
2022-10-20 15:55:07 +03:00
committed by GitHub
parent 39444b0291
commit d62640c56d
12 changed files with 60 additions and 60 deletions
@@ -16,6 +16,7 @@
import UIKit
import MatrixSDK
import SwiftUI
@objc protocol SizableBaseRoomCellType: BaseRoomCellProtocol {
static func sizingViewHeightHashValue(from bubbleCellData: MXKRoomBubbleCellData) -> Int
@@ -35,6 +36,7 @@ class SizableBaseRoomCell: BaseRoomCell, SizableBaseRoomCellType {
private static let reactionsViewModelBuilder = RoomReactionsViewModelBuilder()
private static let urlPreviewViewSizer = URLPreviewViewSizer()
private var contentVC: UIViewController?
private class var sizingView: SizableBaseRoomCell {
let sizingView: SizableBaseRoomCell
@@ -115,6 +117,10 @@ class SizableBaseRoomCell: BaseRoomCell, SizableBaseRoomCellType {
sizingView.setNeedsLayout()
sizingView.layoutIfNeeded()
if let contentVC = sizingView.contentVC as? UIHostingController<AnyView> {
contentVC.view.invalidateIntrinsicContentSize()
}
let fittingSize = CGSize(width: width, height: UIView.layoutFittingCompressedSize.height)
var height = sizingView.systemLayoutSizeFitting(fittingSize).height
@@ -168,4 +174,24 @@ class SizableBaseRoomCell: BaseRoomCell, SizableBaseRoomCellType {
return height
}
func addContentViewController(_ controller: UIViewController, on contentView: UIView) {
controller.view.invalidateIntrinsicContentSize()
let parent = vc_parentViewController
parent?.addChild(controller)
contentView.vc_addSubViewMatchingParent(controller.view)
controller.didMove(toParent: parent)
contentVC = controller
}
override func prepareForReuse() {
contentVC?.removeFromParent()
contentVC?.view.removeFromSuperview()
contentVC?.didMove(toParent: nil)
contentVC = nil
super.prepareForReuse()
}
}