@@ -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
@@ -177,21 +177,21 @@ open class FluidViewController: FluidGestureHandlingViewController, UINavigation
177177 navigationBar. delegate = self
178178
179179 subscriptions. append (
180- navigationBar. observe ( \. bounds, options: [ . initial, . old, . new] ) { [ weak self, topPadding = navigation . topPadding ] view, _ in
180+ navigationBar. observe ( \. bounds, options: [ . initial, . old, . new] ) { [ weak self] view, _ in
181181 guard let self else { return }
182182 MainActor . assumeIsolated {
183- self . additionalSafeAreaInsets. top = view. intrinsicContentSize. height + topPadding
183+ self . additionalSafeAreaInsets. top = view. intrinsicContentSize. height + navigation . _topPaddingProvider ( self )
184184 view. invalidateIntrinsicContentSize ( )
185185 }
186186 }
187187
188188 )
189189
190190 subscriptions. append (
191- navigationBar. observe ( \. intrinsicContentSize, options: [ . initial, . old, . new] ) { [ weak self, topPadding = navigation . topPadding ] view, _ in
191+ navigationBar. observe ( \. intrinsicContentSize, options: [ . initial, . old, . new] ) { [ weak self] view, _ in
192192 guard let self else { return }
193193 MainActor . assumeIsolated {
194- self . additionalSafeAreaInsets. top = view. intrinsicContentSize. height + topPadding
194+ self . additionalSafeAreaInsets. top = view. intrinsicContentSize. height + navigation . _topPaddingProvider ( self )
195195 view. invalidateIntrinsicContentSize ( )
196196 }
197197 }
@@ -288,10 +288,8 @@ open class FluidViewController: FluidGestureHandlingViewController, UINavigation
288288
289289 if !state. isTopBarHidden && state. isTopBarAvailable {
290290 topBar. isHidden = false
291- if case . navigation( let nav) = configuration. topBar {
292- additionalSafeAreaInsets. top = topBar. intrinsicContentSize. height + nav. topPadding
293- } else {
294- additionalSafeAreaInsets. top = topBar. intrinsicContentSize. height
291+ if case . navigation( let navigation) = configuration. topBar {
292+ additionalSafeAreaInsets. top = topBar. intrinsicContentSize. height + navigation. _topPaddingProvider ( self )
295293 }
296294 topBar. invalidateIntrinsicContentSize ( )
297295 } else {
@@ -462,27 +460,29 @@ extension FluidViewController {
462460
463461 public let navigationBarClass : UINavigationBar . Type
464462
465- /// Additional value to add to `additionalSafeAreaInsets.top`.
466- /// Use this to match System Sheet's UINavigationBar height (56pt vs 44pt).
467- public var topPadding : CGFloat
468-
469463 let _activityHandler : @Sendable @MainActor ( Activity < UINavigationBar > ) -> Void
470464
465+ let _topPaddingProvider : @Sendable @MainActor ( FluidViewController ) -> CGFloat
466+
471467 /// Initializer
472468 ///
473469 /// - Parameters:
474- /// - 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.
475475 public init < NavigationBar: UINavigationBar > (
476476 displayMode: DisplayMode = . automatic,
477477 usesBodyViewController: Bool = true ,
478478 navigationBarClass: NavigationBar . Type ,
479- topPadding : CGFloat = 0 ,
479+ topPaddingProvider : @escaping @ MainActor @ Sendable ( FluidViewController ) -> CGFloat = { _ in 0 } ,
480480 activityHandler: @escaping @MainActor ( Activity < NavigationBar > ) -> Void = { _ in }
481481 ) {
482482 self . displayMode = displayMode
483483 self . usesBodyViewController = usesBodyViewController
484484 self . navigationBarClass = navigationBarClass
485- self . topPadding = topPadding
485+ self . _topPaddingProvider = topPaddingProvider
486486 self . _activityHandler = { activity in
487487 switch activity {
488488 case . didLoad( let controller, let navigationBar) :
@@ -492,15 +492,13 @@ extension FluidViewController {
492492 }
493493 }
494494 }
495-
495+
496496 public static let `default` : Self = . init(
497497 displayMode: . automatic,
498498 usesBodyViewController: true ,
499499 navigationBarClass: UINavigationBar . self,
500- topPadding: 0 ,
501- activityHandler: { _ in
502-
503- }
500+ topPaddingProvider: { _ in 0 } ,
501+ activityHandler: { _ in }
504502 )
505503
506504 }
0 commit comments