Skip to content

Commit

Permalink
Merge pull request #96 from ky-is/fix-navigation-empty-title-space
Browse files Browse the repository at this point in the history
Fix blank navigation title space when title is unset
  • Loading branch information
aabewhite authored Dec 29, 2024
2 parents 01b2dc1 + d06acb2 commit cbf7424
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions Sources/SkipUI/SkipUI/Containers/Navigation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,8 @@ public struct NavigationStack<Root> : View where Root: View {
let topBarPreferences = arguments.toolbarPreferences.navigationBar
let topBarHidden = remember { mutableStateOf(false) }
let bottomBarPreferences = arguments.toolbarPreferences.bottomBar
let effectiveTitleDisplayMode = navigator.value.titleDisplayMode(for: arguments.state, preference: arguments.toolbarPreferences.titleDisplayMode)
let hasTitle = arguments.title != NavigationTitlePreferenceKey.defaultValue
let effectiveTitleDisplayMode = navigator.value.titleDisplayMode(for: arguments.state, hasTitle: hasTitle, preference: arguments.toolbarPreferences.titleDisplayMode)
let isInlineTitleDisplayMode = useInlineTitleDisplayMode(for: effectiveTitleDisplayMode, safeArea: arguments.safeArea)
let toolbarItems = ToolbarItems(content: arguments.toolbarPreferences.content ?? [])

Expand Down Expand Up @@ -245,7 +246,7 @@ public struct NavigationStack<Root> : View where Root: View {
}
let topLeadingItems = toolbarItems.filterTopBarLeading()
let topTrailingItems = toolbarItems.filterTopBarTrailing()
guard !arguments.isRoot || arguments.title != NavigationTitlePreferenceKey.defaultValue || !topLeadingItems.isEmpty || !topTrailingItems.isEmpty || topBarPreferences?.visibility == Visibility.visible else {
guard !arguments.isRoot || hasTitle || !topLeadingItems.isEmpty || !topTrailingItems.isEmpty || topBarPreferences?.visibility == Visibility.visible else {
SideEffect {
topBarHidden.value = true
topBarBottomPx.value = Float(0.0)
Expand Down Expand Up @@ -677,12 +678,17 @@ struct NavigationDestination {
}

/// The effective title display mode for the given preference value.
func titleDisplayMode(for state: BackStackState, preference: ToolbarTitleDisplayMode?) -> ToolbarTitleDisplayMode {
func titleDisplayMode(for state: BackStackState, hasTitle: Bool, preference: ToolbarTitleDisplayMode?) -> ToolbarTitleDisplayMode {
if let preference {
state.titleDisplayMode = preference
return preference
}

// Never add large title space when `title` and `titleDisplayMode` are unset in the current stack
guard hasTitle else {
return .inline
}

// Base the display mode on the back stack
var titleDisplayMode: ToolbarTitleDisplayMode? = nil
for entry in navController.currentBackStack.value {
Expand Down

0 comments on commit cbf7424

Please sign in to comment.