@@ -102,7 +102,7 @@ open class FluidViewController: FluidGestureHandlingViewController, UINavigation
102102 }
103103
104104 // MARK: - Functions
105-
105+
106106 @objc
107107 open func triggerFluidPop( ) {
108108 fluidPop ( transition: nil )
@@ -161,7 +161,7 @@ open class FluidViewController: FluidGestureHandlingViewController, UINavigation
161161 }
162162
163163 // MARK: - UIViewController
164-
164+
165165 open override func viewDidLoad( ) {
166166 super. viewDidLoad ( )
167167
@@ -179,20 +179,34 @@ open class FluidViewController: FluidGestureHandlingViewController, UINavigation
179179 subscriptions. append (
180180 navigationBar. observe ( \. bounds, options: [ . initial, . old, . new] ) { [ weak self] view, _ in
181181 guard let self else { return }
182- self . additionalSafeAreaInsets. top = view. frame. height
182+ MainActor . assumeIsolated {
183+ self . additionalSafeAreaInsets. top = view. intrinsicContentSize. height + navigation. _topPaddingProvider ( self )
184+ view. invalidateIntrinsicContentSize ( )
185+ }
183186 }
184- )
185187
186- view . addSubview ( navigationBar )
188+ )
187189
190+ subscriptions. append (
191+ navigationBar. observe ( \. intrinsicContentSize, options: [ . initial, . old, . new] ) { [ weak self] view, _ in
192+ guard let self else { return }
193+ MainActor . assumeIsolated {
194+ self . additionalSafeAreaInsets. top = view. intrinsicContentSize. height + navigation. _topPaddingProvider ( self )
195+ view. invalidateIntrinsicContentSize ( )
196+ }
197+ }
198+ )
199+
188200 navigationBar. translatesAutoresizingMaskIntoConstraints = false
201+
202+ view. addSubview ( navigationBar)
189203
190204 NSLayoutConstraint . activate ( [
191205 navigationBar. bottomAnchor. constraint ( equalTo: view. safeAreaLayoutGuide. topAnchor) ,
192206 navigationBar. rightAnchor. constraint ( equalTo: view. rightAnchor) ,
193207 navigationBar. leftAnchor. constraint ( equalTo: view. leftAnchor) ,
194208 ] )
195-
209+
196210 let targetNavigationItem =
197211 navigation. usesBodyViewController
198212 ? ( content. bodyViewController? . navigationItem ?? navigationItem) : navigationItem
@@ -274,7 +288,10 @@ open class FluidViewController: FluidGestureHandlingViewController, UINavigation
274288
275289 if !state. isTopBarHidden && state. isTopBarAvailable {
276290 topBar. isHidden = false
277- additionalSafeAreaInsets. top = topBar. frame. height
291+ if case . navigation( let navigation) = configuration. topBar {
292+ additionalSafeAreaInsets. top = topBar. intrinsicContentSize. height + navigation. _topPaddingProvider ( self )
293+ }
294+ topBar. invalidateIntrinsicContentSize ( )
278295 } else {
279296 topBar. isHidden = true
280297 additionalSafeAreaInsets. top = 0
@@ -445,19 +462,27 @@ extension FluidViewController {
445462
446463 let _activityHandler : @Sendable @MainActor ( Activity < UINavigationBar > ) -> Void
447464
465+ let _topPaddingProvider : @Sendable @MainActor ( FluidViewController ) -> CGFloat
466+
448467 /// Initializer
449468 ///
450469 /// - Parameters:
451- /// - updateNavigationBar: A closure to update the navigation bar with the owner.
470+ /// - displayMode: Controls when the navigation bar is visible.
471+ /// - usesBodyViewController: Whether to use the body view controller's navigation item.
472+ /// - navigationBarClass: The class of navigation bar to use.
473+ /// - topPaddingProvider: A closure that returns additional top padding above the navigation bar.
474+ /// - activityHandler: A closure called when navigation bar lifecycle events occur.
452475 public init < NavigationBar: UINavigationBar > (
453476 displayMode: DisplayMode = . automatic,
454477 usesBodyViewController: Bool = true ,
455478 navigationBarClass: NavigationBar . Type ,
479+ topPaddingProvider: @escaping @MainActor @Sendable ( FluidViewController ) -> CGFloat = { _ in 0 } ,
456480 activityHandler: @escaping @MainActor ( Activity < NavigationBar > ) -> Void = { _ in }
457481 ) {
458482 self . displayMode = displayMode
459483 self . usesBodyViewController = usesBodyViewController
460484 self . navigationBarClass = navigationBarClass
485+ self . _topPaddingProvider = topPaddingProvider
461486 self . _activityHandler = { activity in
462487 switch activity {
463488 case . didLoad( let controller, let navigationBar) :
@@ -467,14 +492,13 @@ extension FluidViewController {
467492 }
468493 }
469494 }
470-
495+
471496 public static let `default` : Self = . init(
472497 displayMode: . automatic,
473498 usesBodyViewController: true ,
474499 navigationBarClass: UINavigationBar . self,
475- activityHandler: { _ in
476-
477- }
500+ topPaddingProvider: { _ in 0 } ,
501+ activityHandler: { _ in }
478502 )
479503
480504 }
0 commit comments