SwiftUI sheet: half height with presentationDetents

SwiftUI sheets explained: how to present a sheet, set a half-height sheet with presentationDetents and dismiss it properly, with code examples.

3 min readby Luca Ring

You present a sheet in SwiftUI with the .sheet modifier, and presentationDetents decides how tall it gets: half height, full height or a custom value. That's how you build the half-height sheets known from Maps or Music in a few lines of code.

This post covers the essential pieces: presenting a sheet, controlling its height, keeping the background usable and dismissing the sheet properly.

Present a sheet with .sheet

A sheet is tied to a Boolean. When it's true the sheet appears, and SwiftUI resets it when the sheet is dismissed:

struct ContentView: View {
    @State private var showsFilter = false

    var body: some View {
        Button("Filter") { showsFilter = true }
            .sheet(isPresented: $showsFilter) {
                FilterView()
            }
    }
}

If the sheet should show a specific object, such as a selected entry, use .sheet(item:). It opens as soon as the value is set and receives that value directly.

Half height with presentationDetents

By default a sheet covers almost the whole screen on iPhone. With presentationDetents you list the heights that are allowed. With more than one value, people can drag the sheet between them:

.sheet(isPresented: $showsFilter) {
    FilterView()
        .presentationDetents([.medium, .large])
        .presentationDragIndicator(.visible)
}

.medium is roughly half the screen height, .large the full height. The small grabber at the top signals that the sheet can be dragged. Detents are available from iOS 16.

Custom heights and an interactive background

Besides the two fixed stops there is .height for a value in points and .fraction for a share of the screen height. The selection binding lets you read and set the current stop in code:

@State private var detent: PresentationDetent = .height(180)

.sheet(isPresented: $showsPlayer) {
    PlayerView()
        .presentationDetents([.height(180), .fraction(0.6), .large], selection: $detent)
        .presentationBackgroundInteraction(.enabled(upThrough: .height(180)))
}

Normally everything behind a sheet is blocked. With presentationBackgroundInteraction (iOS 16.4 and later) the content behind stays usable while the sheet is small. That suits maps, players or tool palettes.

Dismiss a sheet and prevent accidental swipes

Inside the sheet you dismiss through the environment, without passing the Boolean down. If the sheet contains a form, interactiveDismissDisabled stops input from being lost through a swipe:

struct FilterView: View {
    @Environment(\.dismiss) private var dismiss

    var body: some View {
        NavigationStack {
            Form { /* fields */ }
                .navigationTitle("Filter")
                .toolbar {
                    Button("Done") { dismiss() }
                }
        }
        .interactiveDismissDisabled()
    }
}

A NavigationStack of its own inside the sheet gives you a title and a toolbar. How navigation works in there is explained in SwiftUI NavigationStack.

Sheet or fullScreenCover?

  • Sheet: for a short side task such as filters, details or a form. The connection to the view behind it stays visible.
  • Half-height sheet: for extra information where the content behind still matters.
  • fullScreenCover: for anything that needs full attention, like a camera or an onboarding flow. It always needs its own button to close.

On iPad and Mac, sheets appear as a window in the center, and detents don't behave the way they do on iPhone. So always test on both device sizes.

How sheets look in the current design is shown in the post about Liquid Glass in SwiftUI.

  • SwiftUI sheet
  • presentationDetents
  • SwiftUI bottom sheet
  • half sheet SwiftUI
  • dismiss sheet SwiftUI
  • fullScreenCover