I’m building a document-based SwiftData app (iPhone/iPad/Mac). Here’s a minimal example of how I’m using DocumentGroup.
DocumentGroup(editing: Trip.self, contentType: .trips) {
ContentView()
}
if #available(iOS 18.0, *) {
DocumentGroupLaunchScene {
NewDocumentButton("New Trip")
}
}
I’m struggling with the toolbar behavior in DocumentGroup apps. My content view uses a TabView, and each tab contains a NavigationSplitView. After I select a document in the document browser, I see my tabs. Regardless of which tab is selected, there’s a navigation bar showing the document name and a back button to the document browser. However, only the first tab shows the disclosure button to rename the document. I’d expect to be able to rename the document anywhere the name is shown.
When I navigate to the detail view of my NavigationSplitView (or when using NavigationView/NavigationStack), I still see that back button to the document browser. When the user taps it, they expect to go back to the previous view, not to the document browser.
What’s really odd is that even sheet or fullScreenCover presentations include these document UI elements in the navigation bar. I can’t get rid of them. Even if I set a title via the toolbar or navigationTitle, the rename disclosure button remains visible.
Do DocumentGroup apps intentionally show their specific navigation bar everywhere? Is this a bug or expected behavior? And is it expected that the rename disclosure button appears only on the first tab of a TabView?
The back (<
) navigation item that allows a user to navigate back to the launch scene, together with the navigation item title that shows the document name and the disclosure button, should always be there when you are on the TabView
.
For a tab that has navigation stack, if you navigate to the detail view, the navigation bar should show the items of detail.
Using the following code as an example:
struct ContentView: View {
var body: some View {
TabView {
Tab("Rectangle", systemImage: "rectangle") {
NavigationStack {
NavigationLink("Tap to see details") {
Text("Details")
.toolbar {
ToolbarItem(placement: .topBarTrailing) {
Button("Add") {
print("Button pressed.")
}
}
}
}
}
}
Tab("Circle", systemImage: "circle") {
NavigationStack {
Text("Circle")
.toolbar {
ToolbarItem(placement: .topBarTrailing) {
Button("Remove") {
print("Button pressed.")
}
}
}
}
}
}
}
}
If you tap the link in the first tab, the UI will go to the detail view, and the navigation bar shows a back (<
) navigation item and the "Add" toolbar item. Tapping the back navigation item goes back to view that has the link, which is the top level view of the navigation stack.
Best,
——
Ziqiao Chen
Worldwide Developer Relations.