iOS Modal Presentations

Mar 07, 2023#ios#swift#swiftui

You display a modal presentation, like an alert, popover, sheet, or confirmation dialog to draw attention to an important narrowly scoped task. Depending on the platform, you might use different components to present these types of modal experiences.

In SwiftUI you use presentation modifiers to show different kinds of modal presentations. You don’t call a method at the moment you want to present the modal. Rather, you define how the presentation looks and the condition under which SwiftUI should present it.

Alerts

An alert gives people critical information they need right away.

Popovers

A popover is a transient view that appears above other content onscreen when people click or tap a control or interactive area. Reserve popovers for wide views; for compact views, use all available screen space by presenting information in a full-screen modal view like a sheet instead.

Sheets

A sheet helps people perform a scoped task that’s closely related to their current context.

Action sheets

An action sheet is a modal view that presents choices related to an action people initiate.

Best practices

  • Present content modally only when there’s a clear benefit.
  • Aim to keep modal tasks simple, short, and narrowly focused.
  • Avoid creating a modal experience that feels like an app within your app.
  • Consider using a full-screen modal style for immersive content.
  • Always give people an obvious way to dismiss a modal view.
  • Avoid data loss by getting confirmation before closing a modal view.
  • Make it easy to identify a modal view’s task.
  • Avoid presenting a modal view on top of another modal view.
  • Ensure that people receive critical information and, if necessary, act on it.