@Environment(\.dismiss) private var dismiss to the presented view and call dismiss() from a button action. The same call pops a pushed view off a NavigationStack or closes a sheet, fullScreenCover or popover. On iOS 13 and 14, use @Environment(\.presentationMode) and call presentationMode.wrappedValue.dismiss() instead.Why this happens
SwiftUI has no imperative pop() or close() method on the view itself. The information about how a view is being presented — pushed onto a navigation stack, shown as a sheet, presented as a full-screen cover — lives in the environment, not in your view struct. So the only supported way to close a view from inside it is to read that environment value and ask it to dismiss.
In the first SwiftUI releases the only handle was @Environment(\.presentationMode), which gives you a Binding<PresentationMode>. Because it is a binding, you had to reach through .wrappedValue before calling dismiss(), which is why so much sample code reads presentationMode.wrappedValue.dismiss().
iOS 15 replaced that with @Environment(\.dismiss), a DismissAction you call directly. It is not a bug and it is not going away — it is simply how SwiftUI models presentation. The one thing to understand is that dismiss() is context-sensitive: it closes whatever presentation the current view belongs to, and does nothing if the view is the root of the window.
How to fix it
1. Use @Environment(\.dismiss) on iOS 15 and later
This is the current API. Declare the environment value in the view that is being presented, then call it from any action.
import SwiftUI
struct SheetView: View {
@Environment(\.dismiss) private var dismiss
var body: some View {
NavigationStack {
Text("Sheet content")
.toolbar {
ToolbarItem(placement: .confirmationAction) {
Button("Done") { dismiss() }
}
}
}
}
}
The presenter keeps a @State flag and does not need to know anything about the dismiss call:
struct ContentView: View {
@State private var isShowingSheet = false
var body: some View {
Button("Show sheet") { isShowingSheet = true }
.sheet(isPresented: $isShowingSheet) {
SheetView()
}
}
}
The same code works inside .fullScreenCover and .popover. You do not need a different API for each one.
2. The same call pops a NavigationStack
Put the environment value in the pushed destination and call it from a button, a toolbar item, or after a save completes:
struct DetailView: View {
@Environment(\.dismiss) private var dismiss
var body: some View {
Button("Back to list") { dismiss() }
}
}
One detail worth knowing: if a view is pushed inside a navigation stack that is itself inside a sheet, dismiss() pops the stack first. Only when there is nothing left to pop does it close the sheet. That is the documented behaviour of DismissAction, and it is usually what you want.
3. Fall back to presentationMode for iOS 13 and 14
If your deployment target is below iOS 15, presentationMode is the only option. It works for both navigation pushes and sheets.
struct LegacyDetailView: View {
@Environment(\.presentationMode) private var presentationMode
var body: some View {
Button("Back") {
presentationMode.wrappedValue.dismiss()
}
}
}
presentationMode is deprecated in favour of dismiss in the iOS 15 SDK, so do not mix the two in new code — pick dismiss unless you genuinely support iOS 14 or earlier.
4. Dismiss from a child view or from outside the view
dismiss is only available inside a view body. When a child view or a model object needs to trigger the close, pass a closure down rather than trying to store the environment value:
struct SaveButton: View {
let onSave: () -> Void
var body: some View {
Button("Save", action: onSave)
}
}
struct EditorView: View {
@Environment(\.dismiss) private var dismiss
var body: some View {
SaveButton { dismiss() }
}
}
If the presenter needs to close the sheet itself — for example after a network call finishes — keep using the @State boolean and set it back to false. That path works on every iOS version and needs no environment value at all.
5. Disable the interactive swipe-down gesture
A sheet can always be dragged down by the user. To block that, add .interactiveDismissDisabled() to the sheet’s content (iOS 15 and later):
.sheet(isPresented: $isShowingSheet) {
SheetView()
.interactiveDismissDisabled()
}
You can pass true conditionally, for example only while a form has unsaved changes. On iOS 13 and 14 there is no supported way to turn the gesture off — present the content with .fullScreenCover instead, which has no drag-to-dismiss behaviour.
How to prevent it
- Use
@Environment(\.dismiss)for anything targeting iOS 15+, and reservepresentationModefor legacy deployment targets. - Never call
dismiss()from the root view of a scene — there is nothing to dismiss and the call silently does nothing. - Keep the
@Stateboolean in the presenter when something other than the presented view needs to close it. - Pass a closure to child views and view models instead of storing a
DismissActionin a long-lived object. - Add
.interactiveDismissDisabled()to any sheet holding unsaved input so a stray swipe cannot throw the work away.
FAQ
Does dismiss() work inside a fullScreenCover?
Yes. DismissAction closes whatever presentation the view belongs to, so the same @Environment(\.dismiss) code works for sheets, full-screen covers and popovers without changes.
Why does my dismiss() call do nothing?
The view is probably not presented — it is the root of the window, or it is embedded in a container that is not a presentation context. Check that the view is actually pushed with NavigationLink or shown through .sheet, .fullScreenCover or .popover.
Can I call dismiss from a view model?
Not directly, because the environment value is only readable inside a View. Expose a closure such as var onFinish: () -> Void on the view model and have the view assign dismiss to it, or drive the presentation from a @State boolean in the presenter.
Parts of this guide are adapted from content licensed under CC BY-SA 4.0; this article is shared under the same license.
