An update: using a minimal example, I've found the sidebar toggle stays visible as desired when applying the .inspector modifier to the NavigationSplitView. The sidebar toggle does not stay visible when applying it to the .detail view.
import SwiftUI
@main struct MyApp: App {
@State var isShowingInspector = false
var body: some Scene {
WindowGroup {
NavigationSplitView(
sidebar: {
Text("Hello Sidebar.")
},
detail: {
Text("Hello Detail.")
.toolbar {
Button(action: { self.isShowingInspector.toggle() }, label: { Text("Toggle Inspector") } )
}
// When using this modifier, the sidebar toggle
// DOES NOT stay visible when the sidebar is hidden.
//
// .inspector(isPresented: $isShowingInspector) {
// Text("Hello Inspector.")
// }
}
)
// When using this modifier, the sidebar toggle stays visible when
// the sidebar is hidden.
//
// .inspector(isPresented: $isShowingInspector) {
// Text("Hello Inspector.")
// }
}
}
}
According to Inspectors in SwiftUI: Discover the details from WWDC23 (starting at 5:55), the .inspector modifier is intended to be flexibly used on either the detail view or the containing navigation view. That section of the talk even ends by emphasizing:
If you are using an inspector within a NavigationSplitView, the inspector should be placed in the detail column's view builder, or, just like before, it can also be placed entirely outside the navigation structure.
So I've wound up supposing this is indeed just a persistent bug.
Topic:
UI Frameworks
SubTopic:
SwiftUI
Tags: