Declaration
compose().presentationSizing(sizing: SwiftUI.PresentationSizing)nonisolated func presentationSizing(
_ sizing: some PresentationSizing
) -> some ViewParameters
sizing*SwiftUI.PresentationSizingA 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 View.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.
- Seealso:
PresentationSizing.fitted(horizontal:vertical:)andPresentationSizing.sticky(horizontal:vertical:).
the proposed width only applies to the detail column. The sidebar
and content column widths use system-provided values, or those from
View.navigationSplitViewColumnWidth(_:) or
View.navigationSplitViewColumnWidth(min:ideal:max:) modifiers.
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
More in Presentation.
- alertPresents an alert when a given condition is true, using a localized string resource for the title.
- confirmationDialogPresents a confirmation dialog when a given condition is true, using a localized string resource for the title.
- contextMenuAdds an item-based context menu to a view.
- dialogIconConfigures the icon used by dialogs within this view.
- dialogSuppressionToggleEnables user suppression of dialogs and alerts presented within self, with a custom suppression message on macOS. Unused on other platforms.
- dismissalConfirmationDialogPresents a confirmation dialog upon an attempt to dismiss the window for this view.
- documentBrowserContextMenuAdds to a DocumentLaunchView actions that accept a list of selected files as their parameter.
- fileDialogBrowserOptionsOn macOS, configures the fileExporter, fileImporter, or fileMover to provide a refined URL search experience: include or exclude hidden files, allow searching by tag, etc.
- fileDialogConfirmationLabelOn macOS, configures the fileExporter, fileImporter, or fileMover with a custom confirmation button label.
- fileDialogCustomizationIDOn macOS, configures the fileExporter, fileImporter, or fileMover to persist and restore the file dialog configuration.
- fileDialogDefaultDirectoryConfigures the fileExporter, fileImporter, or fileMover to open with the specified default directory.
- fileDialogImportsUnresolvedAliasesOn macOS, configures the fileExporter, fileImporter, or fileMover behavior when a user chooses an alias.