Skip to content

Popup Dismissal

Tomasz K. edited this page Nov 17, 2024 · 33 revisions

Przez chwilę nic się nie działo. Potem - po jakiejś sekundzie - nadal nic się nie działo.

Popup Dismissal

Overview

Dismissing a popup can be done in two ways - If you are working within the context of a View, simply call one of the functions described below. Otherwise (e.g., if you want to dismiss the popup from a ViewModel), prefix the method name with the PopupStack class. For the sake of clarity, we will use both ways in the code examples below.

Available Methods

Important

All the methods below take an optional argument, popupStackID, which specifies the ID of the popup stack registered for a specific window (see Setup and Popup Presentation pages for the reference). If more than one popup stack is registered, please ensure that you are dismissing the popup from the correct stack.

  • func dismissLastPopup(popupStackID: PopupStackID = .shared) async
    • Dismisses the currently active popup.
  • func dismissPopup(_ id: String, popupStackID: PopupStackID = .shared) async
    • Dismisses all popups with the specified identifier from the stack.
  • func dismissPopup<P: Popup>(_ type: P.Type, popupStackID: PopupStackID = .shared) async
    • Dismisses all popups of the provided type from the stack.
  • func dismissAllPopups(popupStackID: PopupStackID = .shared) async
    • Dismisses all popups from the stack.

Usage

Dismissing the active popup

// Inside a View
Button(action: { Task { await dismissLastPopup() }}) {
    Text("Dismiss Popup")
}
// Outside a View
await PopupStack.dismissLastPopup()

Dismissing all the popups of a specified ID

// Inside a View
Button(action: { Task { await dismissPopup("customPopupIdentifier") }}) {
    Text("Dismiss Popup")
}
// Outside a View
await PopupStack.dismissPopup("customPopupIdentifier")

Dismissing all the popups of a specified type

// Inside a View
Button(action: { Task { await dismissPopup(MyPopup.self) }}) {
    Text("Dismiss Popup")
}
// Outside a View
await PopupStack.dismissPopup(MyPopup.self)

Dismissing all the popups

// Inside a View
Button(action: { Task { await dismissAllPopups() }}) {
    Text("Dismiss Popup")
}
// Outside a View
await PopupStack.dismissAllPopups()

See also