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.
Choose an adaptation constant
PresentationAdaptation exposes named cases that describe the target form:
automaticlets SwiftUI decide,nonesuppresses adaptation so the presentation keeps its current form, and cases likepopover,sheet, andfullScreenCoverrequest a specific form. In the example,.noneis selected to stop the presentation from morphing as the size class changes.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.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.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.
.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.
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])
}
}
}