Contents

presentationSizing(_:)

Sets the sizing of the containing presentation.

Declaration

nonisolated func presentationSizing(_ sizing: some PresentationSizing) -> some View

Parameters

  • sizing:

    A value dictating size to propose to presentation content and how the presentation responds to changes in content size.

Discussion

Use this modifier to apply a PresentationSizing to a presentation like sheet(isPresented:onDismiss:content:). The sizing parameter defines the size proposed to the content, and the presentation adopts the returned size. The default value is automatic.

Sizings can be modified to fix their dimensions based on the content, and optionally be sticky.

For example, a presentation with facts about flowers could prefer .page sizing because its content is primarily informational. Since the user can choose different flowers from the picker, each with different lengths of information, the size is fitted vertically to size the sheet to the textual content, and vertically sticky is specified to prevent the presentation from changing size too frequently as the user changes selection.

struct ContentView: View {
    @State private var presentInfo = true

    var body: some View {
        ContentView.sheet(isPresented: $presentInfo) {
            VStack {
                Picker("Flower Species", selection: $flower) {
                    ForEach(Flower.allCases) {
                        Text($0.rawValue.uppercased()).tag($0)
                    }
                }
                Text(flower.emoji).font(.largeTitle)
                Text(flower.informationalText)
            }
            .frame(maxHeight: .infinity, alignment: .top)
            .padding()
            .presentationSizing(
                .page
                    .fitted(horizontal: false, vertical: true)
                    .sticky(horizontal: false, vertical: true))
        }
    }
}

See Also

Adapting a presentation size