get rid of additional UIHostingController. Cleanup and comments.

This commit is contained in:
David Langley
2022-10-12 14:14:25 +01:00
parent e525bd84f9
commit 89c643734c
9 changed files with 93 additions and 56 deletions
@@ -16,6 +16,7 @@
import Foundation
import SwiftUI
import Combine
/**
UIHostingController that applies some app-level specific configuration
@@ -25,7 +26,9 @@ class VectorHostingController: UIHostingController<AnyView> {
// MARK: Private
private let forceZeroSafeAreaInsets: Bool
private var theme: Theme
private var heightSubject = CurrentValueSubject<CGFloat, Never>(0)
// MARK: Public
@@ -40,8 +43,12 @@ class VectorHostingController: UIHostingController<AnyView> {
var enableNavigationBarScrollEdgeAppearance = false
/// When non-nil, the style will be applied to the status bar.
var statusBarStyle: UIStatusBarStyle?
private let forceZeroSafeAreaInsets: Bool
/// Whether or not to publish when the height of the view changes
var publishHeightChanges: Bool = false
/// The publisher to subscribe to if `publishHeightChanges` is enabled.vi
var heightPublisher: AnyPublisher<CGFloat, Never> {
return heightSubject.eraseToAnyPublisher()
}
override var preferredStatusBarStyle: UIStatusBarStyle {
statusBarStyle ?? super.preferredStatusBarStyle
@@ -104,6 +111,10 @@ class VectorHostingController: UIHostingController<AnyView> {
if #available(iOS 15.0, *) {
self.view.invalidateIntrinsicContentSize()
}
if publishHeightChanges {
let height = sizeThatFits(in: CGSize(width: self.view.frame.width, height: UIView.layoutFittingExpandedSize.height)).height
heightSubject.send(height)
}
}
override func viewSafeAreaInsetsDidChange() {