Usually, you possibly can programatically shut and open a popover with popover(isPresented: Binding, like so:
struct AContent: View {
@State personal var showFilter = false
var physique: some View {
VStack(spacing: 16) {
Button("Filter") {
showFilter = true
}
.popover(isPresented: $showFilter, arrowEdge: .backside) {
VStack(spacing: 16) {
Button("One") {
showFilter = false // dismiss
}
Button("Two") {
showFilter = false
}
}
.padding(24)
.presentationCompactAdaptation(.popover)
}
}
}
}
Urgent Button “One” or Button “Two” will shut the popover.
Nonetheless, the difficulty I am going through is that it does not work if it is inside a navigation stack. Based mostly on this reproducible code:
struct A: View {
@State personal var path = NavigationPath()
var physique: some View {
NavigationStack(path: $path) {
Button("Go to filter display") {
path.append("display")
}
.navigationDestination(for: String.self) { _ in
AContent()
}
}
}
}
@predominant
struct MyApp: App {
var physique: some Scene {
WindowGroup {
A()
}
}
}
The popover is just not closing after I choose any of the choices within the popover. I wish to know the explanation why that is taking place. I examined it being inside a TabView, and it really works simply advantageous, but it surely doesn’t work contained in the NavigationStack.
