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 8b14400b2c
commit 3f7622dd5c
12 changed files with 60 additions and 60 deletions
@@ -25,8 +25,7 @@ import Combine
class VectorHostingController: UIHostingController<AnyView> {
// MARK: Private
private let forceZeroSafeAreaInsets: Bool
private var theme: Theme
private var heightSubject = CurrentValueSubject<CGFloat, Never>(0)
@@ -55,11 +54,8 @@ class VectorHostingController: UIHostingController<AnyView> {
}
/// Initializer
/// - Parameter rootView: Root view for the controller.
/// - Parameter forceZeroSafeAreaInsets: Whether to force-set the hosting view's safe area insets to zero. Useful when the view is used as part of a table view.
init<Content>(rootView: Content,
forceZeroSafeAreaInsets: Bool = false) where Content: View {
init<Content>(rootView: Content) where Content: View {
self.theme = ThemeService.shared().theme
self.forceZeroSafeAreaInsets = forceZeroSafeAreaInsets
super.init(rootView: AnyView(rootView.vectorContent()))
}
@@ -116,22 +112,6 @@ class VectorHostingController: UIHostingController<AnyView> {
heightSubject.send(height)
}
}
override func viewSafeAreaInsetsDidChange() {
super.viewSafeAreaInsetsDidChange()
guard forceZeroSafeAreaInsets else {
return
}
let counterSafeAreaInsets = UIEdgeInsets(top: -view.safeAreaInsets.top,
left: -view.safeAreaInsets.left,
bottom: -view.safeAreaInsets.bottom,
right: -view.safeAreaInsets.right)
if additionalSafeAreaInsets != counterSafeAreaInsets, counterSafeAreaInsets != .zero {
additionalSafeAreaInsets = counterSafeAreaInsets
}
}
private func registerThemeServiceDidChangeThemeNotification() {
NotificationCenter.default.addObserver(self, selector: #selector(themeDidChange), name: .themeServiceDidChangeTheme, object: nil)