-
-
Notifications
You must be signed in to change notification settings - Fork 68
Popup Presentation
Dziś musi być czwartek. Nigdy nie mogłem się połapać, o co chodzi w czwartki.
Presenting a popup is as simple as using the .present()
method with your defined Popup structure (see Popup Declaration page for the reference). Furthermore, there are several other methods available that can be used to better meet your specific requirements.
-
func present(popupStackID: PopupStackID = .shared) async
- Displays the popup in the application window identified by popupStackID (see Setup page for the reference).
-
func setCustomID(_ id: String) async -> some Popup
- Optional
- Assigns a custom identifier to a popup, allowing for more precise control over individual popups, especially useful if you need to manage multiple popups of the same type.
-
func setEnvironmentObject<T: ObservableObject>(_ object: T) async -> some Popup
- Optional
- Supplies an observable object to a popup's view hierarchy. This allows the popup to access and observe changes in the provided object.
-
func dismissAfter(_ seconds: Double) async -> some Popup
- Optional
- Automatically dismisses the popup after a specified period of time.
-
Declare a popup. See Popup Declaration page for the reference
-
Call the
present()
method on an instance of your custom popup view to display itclass SettingsViewModel: ObservableObject { func saveSettings() { (...) Task { await BottomCustomPopup().present() } } }
-
(Optional) The
present()
method can also be called with a custompopupStackID
. To do so, first register the popupStackID during the setup and then call thepresent()
method with the registered ID@main struct MyApp: App { var body: some Scene { WindowGroup { ContentView().registerPopups(id: .custom1) } } } extension PopupStackID { static let custom1: Self = .init(rawValue: "custom1") } class SettingsViewModel: ObservableObject { func saveSettings() { (...) Task { await BottomCustomPopup().present(popupStackID: .custom1) } } }
-
(Optional) Call
setCustomID()
methodclass SettingsViewModel: ObservableObject { func saveSettings() { (...) Task { await BottomCustomPopup() .setCustomID("customID") .present() } } }
-
(Optional) Call
setEnvironmentObject()
methodstruct ContentView: View { @StateObject var myObject = MyObservableObject() var body: some View { Button("Show Popup") { Task { await BottomCustomPopup() .setEnvironmentObject(myObject) .present(popupStackID: .custom1) } } } }
-
(Optional) Call
dismissAfter()
methodclass SettingsViewModel: ObservableObject { func saveSettings() { (...) Task { await BottomCustomPopup() .setCustomID("customID") .dismissAfter(5) .present() } } }