I have a safe area inset view that is placed on my NavigationStack
so that acts as a bottom bar across all pushed views. However, in the safe area inset view, there are button which I'd like to push views onto the stack. The NavigationLink
is greyed out though since it is outside of a NavigationStack
.
This is what my code looks like:
NavigationStack {
VStack {
Image(systemName: "globe")
Text("Hello, world!")
}
.toolbar {
ToolbarItem(placement: .navigationBarLeading) {
NavigationLink("Button 1") {
Text("Screen 1")
}
}
ToolbarItem(placement: .navigationBarTrailing) {
NavigationLink("Button 2") {
Text("Screen 2")
}
}
}
}
.safeAreaInset(edge: .bottom, spacing: 0) {
HStack {
NavigationLink("Button 1") {
Text("Screen 1")
}
.frame(minWidth: 0, maxWidth: .infinity)
NavigationLink("Button 2") {
Text("Screen 2")
}
.frame(minWidth: 0, maxWidth: .infinity)
}
.padding()
.background(.regularMaterial)
}
It behaves in a way where the bottom view does indeed stick across all pushed views, but the buttons there do not do anything (the ones in the top navigation bar work properly though):
How can I get the buttons in the bottom safe area inset to navigation to different screens while still keeping it on the NavigationStack
level since I do not want to place this bottom overlay code on each sub view?