How it works
PresentationSizingRoot represents the root of a presentation as it is being measured, giving a custom PresentationSizing type a concrete proposal and a place to attach the resolved size. When you supply your own sizing behavior to a sheet or other presentation, SwiftUI hands you this root so you can compute how large the presentation should be and report that size back up. Reach for it when the built-in presentation sizes don't fit your content and you need to drive the measurement yourself rather than letting the system pick.
Choose a sizing through presentationSizing(_:)
Apply the presentationSizing(_:) modifier to the presented content to install a PresentationSizing value that participates in measuring the root. In the example it is attached to the sheet's VStack with .presentationSizing(.form.fitted(horizontal: false, vertical: true)).
Start from a built-in sizing base
PresentationSizing offers ready-made bases such as .form, .page, and .automatic that define a default footprint for the root before you refine it. The example begins with .form, the size SwiftUI uses for form-style presentations, as the starting point for sizing the root.
Refine the root with fitted(horizontal:vertical:)
The fitted(horizontal:vertical:) modifier tells the sizing to shrink the root to its content along the chosen axes instead of filling the proposed space. Here .fitted(horizontal: false, vertical: true) keeps the form's standard width but lets the root collapse vertically to wrap the two Text lines.
Bound the measurement to a real presentation
PresentationSizingRoot only exists while an actual presentation is on screen, so the sizing takes effect inside a presentation container. In the example the sheet(isPresented:) presentation driven by the $showing state is what brings the root into being and applies the resolved size to it.
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 PresentationSizingRootDemo: View {
@State private var showing = true
var body: some View {
Text("Host View")
.padding()
.sheet(isPresented: $showing) {
VStack(spacing: 12) {
Text("Sized Sheet")
.font(.headline)
Text("This sheet is laid out by a custom\nPresentationSizing using its root.")
.multilineTextAlignment(.center)
}
.padding()
.presentationSizing(.form.fitted(horizontal: false, vertical: true))
}
}
}