I discovered a really weird issue with the title on the sidebar on iPads. I've set the navigationBarTitleDisplayMode to .large, but on first load (right after I run the app on the simulator), the title is shown as inline but if I pull the list downwards (scrolling up), the title becomes large. It's as if the list is scrolled up on first load. But the list is fully visible so it doesn't really appear like it was scrolled. I hope my explanation makes sense.
Here's a sample code:
NavigationSplitView {
VStack {
List(folders, id: \.self, selection: $selectedFolder) { folder in
NavigationLink(folder.title, value: folder)
}
.navigationTitle("Test Title")
.navigationBarTitleDisplayMode(.large)
Spacer()
Button {
//Create new list
newListModalShown = true
} label: {
Text("New List")
}
}
} detail: {
if let selectedFolder {
ItemsListView(folder: selectedFolder)
} else {
Text("Select a list")
.navigationTitle("")
.navigationBarTitleDisplayMode(.inline)
}
}
Here are some screenshots of the UI:
I've done a few troubleshooting steps to check what's causing the problem, unfortunately, I've not figured it out:
I am hoping it's just not me who experienced this problem. I'd be happy to report this as a bug if indeed it is. Just wanted to know if anybody else had found a work around.
Thanks!
Update: Went with @Benzy Neez's solution #1. Both suggested workarounds worked, but solution #1 aligned more with what I wanted to implement.
I agree that it looks like a bug.
Here are some workarounds:
1. Launch the view with the sidebar visible
The title is large if the sidebar is visible when the view is first shown:
@State private var visibility = NavigationSplitViewVisibility.doubleColumn
NavigationSplitView(columnVisibility: $visibility) {
// ...
}
2. Show the title as a section header instead
If the List
is wrapped with a Section
, the title can be shown as the section header:
Section {
List(folders, id: \.self, selection: $selectedFolder) { folder in
NavigationLink(folder.title, value: folder)
}
.navigationBarTitleDisplayMode(.inline)
.navigationTitle("")
} header: {
Text("Test Title")
.padding(.leading, 20)
.frame(maxWidth: .infinity, alignment: .leading)
.font(.largeTitle)
.fontWeight(.bold)
}