I am trying to dismiss a fullscreenCover(..) that is nested within a TabView and a NavigationView. I want it to be dismissed by invaliding a parent-view of the view invoking fullScreenCover(..).
For example this view hierarchy works fine and dismisses fullScreenCover on invaliding view X:
- X -> A -> fullScreenCover
This view hierarchy does not dismiss fullScreenCover on invalidating view X:
- X -> NavigationView -> A -> fullScreenCover
It seems like fullScreenCover uses UIKit under the hood, and that the PresentationHostingController does not get dismissed properly when a NavigationView is used. I provided some example code that shows the problem:
struct ContentView: View {
@State var viewFullScreen: Bool = false
@State var showViewA: Bool = true
var body: some View {
if showViewA {
NavigationView{
Button("Trigger fullscreen") { viewFullScreen.toggle() }
.fullScreenCover(isPresented: $viewFullScreen) {
Button("Go to B", action: {
self.showViewA = false //Not working when embedded in NavigationView
})
}
}
} else {
Text("View B")
}
}
}