PresentationSizing

A type that defines the size of the presentation content and how the presentation size adjusts to its content's size changing.

ProtocoliOS 18.0+macOS 15.0+tvOS 18.0+watchOS 11.0+visionOS 2.0+PresentationSizing in SwiftUI

Declaration

React
type PresentationSizing =
  | 'automatic'
  | 'fitted'
  | 'form'
  | 'page'
  | PresentationSizingChain;
Swift
protocol PresentationSizing

Pass a literal, or build one with SwiftUI.PresentationSizing from import { SwiftUI } from 'swiftui-react-native'.

Type properties

Overview

You don't need to define your own version of this protocol. The system implementations of PresentationSizing.form, PresentationSizing.page, and PresentationSizing.fitted are conveniences that automatically adapt to different device and screen sizes. If you do want to define your own sizing, first consider using the modifiers PresenationSizing.sticky(horizontal:vertical:) and PresentationSizing.fitted(horizontal:vertical:). For example, to define your own sizing that proposes a 400x400 square size:

protocol SquareSizing: PresentationSizing {
    func proposedSize(
        for subview: PresentationSizingRoot,
        context: PresentationSizingContext
    ) {
        .init(width: 400, height: 400)
    }
}

extension PresentationSizing where Self == SquareSizing {
    public static var square: Self { SquareSizing() }
}

Then, at the callsite, you can modify .square just like system sizings, for example, to fit its content vertically:

.presentationSizing(.square.fitted(horizontal: false, vertical: true))

From Apple’s SwiftUI documentation. Code samples there are Swift.

Used by

See also

More in Presentation.