StackNavigationView
A SwiftUI component for macOS that makes complex view hierarchies possible
Install / Use
/learn @lbrndnr/StackNavigationViewREADME
StackNavigationView
⚠️ SwiftUI now supports NavigationStack, making this repo redundant for new projects. I recommend to only use this if you have to support macOS 11 or 12. ⚠️
About
As of SwiftUI v2, NavigationView only supports a simple sidebar selection. This makes it impossible to push new views onto the view hierarchy, as one could do e.g. with UINavigationController. This project is a workaround that builds upon NavigationView to support complex view hierarchies.

Usage
The interface of StackNavigationView is very similar to the one of NavigationView, just make sure not to use NavigationLink inside of StackNavigationView though, it will result in undefined behaviour. You'll find the full example here.
struct ContentView: View {
@State private var selection: Int? = 0
var body: some View {
return StackNavigationView(selection: $selection) {
List {
SidebarNavigationLink("Apples", destination: rootView(title: "Apples"), tag: 0, selection: $selection)
SidebarNavigationLink("Bananas", destination: rootView(title: "Bananas"), tag: 1, selection: $selection)
SidebarNavigationLink("Clementines", destination: rootView(title: "Clementines"), tag: 2, selection: $selection)
}
Text("Empty Selection")
}
.frame(minWidth: 600, minHeight: 400)
}
@ViewBuilder private func rootView(title: String) -> some View {
VStack {
Text("This is the root view of \(title)")
.font(.system(size: 50))
.bold()
Spacer()
.frame(height: 40)
StackNavigationLink("Next", destination: ChildView(sidebar: title, level: 1))
}
.padding(20)
.navigationTitle(title)
}
}
Requirements
StackNavigationView is a SwiftUI component for macOS. macOS Big Sur is required.
Author
I'm Laurin Brandner, I'm on Twitter.
License
StackNavigationView is licensed under the MIT License.
Related Skills
node-connect
345.9kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
106.4kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
345.9kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
345.9kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
