TechnologiesSwiftUIPresentation and Dialogs

PresentationSizing protocol

iOSmacOStvOSwatchOSvisionOSiOS 18.0+✓ renders

A type that defines the size of the presentation content and how the

How it works

PresentationSizing is the protocol SwiftUI uses to decide how large a presented view—such as a sheet or popover—should be. Rather than letting a presentation default to its content's intrinsic size or fill the screen, you adopt a presentation sizing to declare an intent: a compact form, a page-filling layout, or a size derived from the content itself. Reach for it when a modally presented view should occupy a predictable, semantically named footprint across the platforms and size classes your app runs on.

  1. Apply a sizing with presentationSizing(_:)

    The presentationSizing(_:) modifier attaches a PresentationSizing value to the content of a presentation, telling the system how to measure and lay out that presentation. You place it on the root view inside the presentation closure, where it governs the enclosing sheet or popover rather than the view it's written on. Here it sits at the end of the modally presented VStack, as .presentationSizing(.form).

  2. Choose a built-in sizing value

    SwiftUI ships standard conformers exposed as static members, so you rarely implement the protocol yourself. .form requests a compact, form-style footprint suited to focused input; companion values like .page and .fitted request a page-filling or content-driven size. The example passes .form, which keeps the sheet small and centered around its Text("Form-sized sheet") content instead of stretching to a full-height sheet.

  3. Pair it with a presentation modifier

    PresentationSizing only takes effect inside an actual presentation, so it travels alongside a presenting modifier like sheet, popover, or fullScreenCover. The sizing is read when the presentation appears and resolved against the available container. In the example the .sheet(isPresented: $showing) modifier supplies the presentation context that .presentationSizing(.form) then sizes.

  4. Refine with sizing(_:) when needed

    Because conformers can be composed, a base PresentationSizing can be adjusted before use—for instance constraining or fitting it to its content—producing another PresentationSizing you pass to the same .presentationSizing(_:) modifier. This lets you start from a semantic value such as .form and tune the resolved dimensions without abandoning the protocol's adaptive behavior.

Try it — Change .presentationSizing(.form) to .presentationSizing(.page) and watch the sheet grow from a compact form into a page-filling presentation.

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.

PresentationSizing.swift
struct PresentationSizingDemo: View {
    @State private var showing = true

    var body: some View {
        Text("Main screen")
            .padding()
            .sheet(isPresented: $showing) {
                VStack(spacing: 12) {
                    Text("Form-sized sheet")
                        .font(.headline)
                    Text("Sized via .presentationSizing(.form)")
                        .foregroundStyle(.secondary)
                }
                .padding()
                .presentationSizing(.form)
            }
    }
}
Live preview
Main screen Form-sized sheet Sized via .presentationSizing(.form)
Main screen Form-sized sheet Sized via .presentationSizing(.form)
swift → lexer → parser → sema → uiir → canvas Open in Studio ↗
What's new in SwiftUI 27 →