Search code examples
swiftswiftui

Dismiss Multiple Modal Sheets


I am using .sheet(isPresented: self.$showModal) in my root view to present a modal. Within the modal, I am using NavigationView to take the user through various pages (for a user profile builder).

In the last page of my navigation stack, I am using @Environment(\.presentationMode) var presentationMode and a button which calls self.presentationMode.wrappedValue.dismiss() to dismiss the modal. However, this only dismisses the last page in the navigation stack, and I just end up at the previous page. What I want to do is dismiss the entire navigation stack and end up back at the root view.

Swiping down to dismiss the modal produces the desired result, but I want to do this programatically with the button.

Is this currently possible in SwiftUI, or is this a problem with using NavigationView within a modal sheet?


Solution

  • You can pass showModal as a binding into the following screens and instead of using presentationValue set showModal to false.