-
-
Notifications
You must be signed in to change notification settings - Fork 92
Popup Declaration
Tomasz K. edited this page Oct 30, 2024
·
49 revisions
Na wszystko, co się zdarzy, masz gotowy, przywieziony z Ziemi schemat. Jeżeli jakiś szczegół nie pasuje, to go po prostu odrzucasz.
The framework provides the ability to present a view as a popup in one of three predefined areas - Top, Centre or Bottom.
The presentation area must be chosen during the popup declaration, by conforming to one of the selected protocols:
-
TopPopup- presents popup view from the top -
CentrePopup- presents popup view from the center -
BottomPopup- presents popup view from the bottom
The TopPopup, CentrePopup and BottomPopup protocols define several methods:
// DESCRIPTION: Defines a view to act as a popup
var body: some View// OPTIONAL
// DESCRIPTION: Configures the popup. If not called, the popup inherits the configuration defined during the setup
func configurePopup(config: Config) -> Config // OPTIONAL
// DESCRIPTION: Triggered every time a popup is at the top of the stack
func onFocus()// OPTIONAL
// DESCRIPTION: Triggered when a popup is dismissed
func onDismiss()- Declare a structure for your Popup
- Decide where the popup will appear: top, center, or bottom.
- Confirm to one of the protocols:
TopPopup,CentrePopup, orBottomPopup.
struct BottomCustomPopup: BottomPopup { ... }
- Declare the
bodyvariable- Define the design of your popup inside the body variable.
struct BottomCustomPopup: BottomPopup { var body: some View { HStack(spacing: 0) { Text("Hello World") Spacer() Button(action: { dismissLastPopup() }) { Text("Dismiss") } } .padding(.vertical, 20) .padding(.leading, 24) .padding(.trailing, 16) } }
- Define the design of your popup inside the body variable.
-
(Optional) Implement
configurePopup(config: Config) -> Configmethod- Customize the popup appearance using configuration methods specific to the popup type.
- The list of available customization methods can be found [here].(Popup-Configuration)
struct BottomCustomPopup: BottomPopup { var body: some View { HStack(spacing: 0) { Text("Hello World") Spacer() Button(action: { dismissLastPopup() }) { Text("Dismiss") } } .padding(.vertical, 20) .padding(.leading, 24) .padding(.trailing, 16) } func configurePopup(config: BottomPopupConfig) -> BottomPopupConfig { config .horizontalPadding(20) .bottomPadding(42) .cornerRadius(16) }
} ```
-
On Dismiss
-
On Focus