TechnologiesSwiftUIPresentation and Dialogs

PresentationAdaptation struct

iOSmacOStvOSwatchOSvisionOSiOS 16.4+✓ renders

Strategies for adapting a presentation to a different size class.

How it works

PresentationAdaptation is a set of constants that tell SwiftUI how a presentation should change its appearance when the available space crosses a size class boundary. By default, a presentation such as a popover or a sheet may switch to a different form in a compact horizontal environment — a popover, for instance, becomes a full sheet on a narrow iPhone. Reach for PresentationAdaptation when you want to override that automatic behavior and pin a presentation to a specific form, or steer it toward another, regardless of the size class. You apply your chosen adaptation through the presentation-adaptation modifiers rather than constructing the type directly.

  1. Choose an adaptation constant

    PresentationAdaptation exposes named cases that describe the target form: automatic lets SwiftUI decide, none suppresses adaptation so the presentation keeps its current form, and cases like popover, sheet, and fullScreenCover request a specific form. In the example, .none is selected to stop the presentation from morphing as the size class changes.

  2. Apply it with presentationCompactAdaptation(_:)

    You attach a PresentationAdaptation to the content of a presentation using the presentationCompactAdaptation(_:) modifier, which governs how that presentation behaves specifically in a compact size class. Here .presentationCompactAdaptation(.none) is placed on the presented VStack, telling SwiftUI not to expand into a full sheet when the width becomes compact.

  3. Control horizontal and vertical independently

    A companion modifier, presentationCompactAdaptation(horizontal:vertical:), accepts two PresentationAdaptation values so you can adapt differently for compact width versus compact height. The single-argument form used in the example, .presentationCompactAdaptation(.none), applies the same adaptation to both axes.

  4. Combine with the rest of the presentation configuration

    PresentationAdaptation sits alongside the other presentation modifiers and refines, rather than replaces, them. In the example it works next to .presentationDetents([.medium]), which still describes the resting size of the presentation when it does appear as a sheet — the adaptation decides the form, the detents describe its sizing.

Try it — Change .presentationCompactAdaptation(.none) to .presentationCompactAdaptation(.sheet) and watch the same presentation expand into a full sheet in compact widths instead of staying compact.

Example & preview

Press Run live & edit to compile it in your browser — then edit the Swift on the left and the preview re-renders live.

PresentationAdaptation.swift
struct PresentationAdaptationDemo: View {
    @State private var showing = true

    var body: some View {
        Text("Adaptive presentation")
            .padding()
            .sheet(isPresented: $showing) {
                VStack(spacing: 12) {
                    Text("Stays a popover in compact widths")
                        .font(.headline)
                    Text("PresentationAdaptation.none keeps this\nfrom expanding to a full sheet.")
                        .multilineTextAlignment(.center)
                        .foregroundStyle(.secondary)
                }
                .padding()
                .presentationCompactAdaptation(.none)
                .presentationDetents([.medium])
            }
    }
}
Live preview
Adaptive presentation Stays a popover in compact widths PresentationAdaptation.no… keeps this\nfrom expanding to a full sheet.
Adaptive presentation Stays a popover in compact widths PresentationAdaptation.no… keeps this\nfrom expanding to a full sheet.
swift → lexer → parser → sema → uiir → canvas Open in Studio ↗
What's new in SwiftUI 27 →