Skip to content

Popup Customization

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

Czas to iluzja - oznajmił. Tym bardziej czas lunchu.

Popup Customization

Overview

Popups can be customized from two places: globally during Setup or individually, during Popup Declaration. If a method with the same name is called locally, then the global setting for that popup will be overridden.

Global

Overview

Allows you to set default behaviors and styles for all popups across your application. The following sections provide an example of use and list the available methods.

Code Example

@main struct App_Main: App {
    var body: some Scene { WindowGroup {
        ContentView()
            .registerPopups { config in config
                .vertical { $0
                    .enableDragGesture(true)
                    .tapOutsideToDismissPopup(true)
                    .cornerRadius(32)
                }
                .center { $0
                    .tapOutsideToDismissPopup(false)
                    .backgroundColor(.white)
                }
            }
    }}
}

Available Methods

  • popupHorizontalPadding(_ value: CGFloat) -> Self

    • Sets the horizontal padding of the popup.
    • For Top, Center and Bottom popups.
  • cornerRadius(_ value: CGFloat) -> Self

    • Sets the corner radius of the popup background.
    • For Top, Center and Bottom popups.
  • backgroundColor(_ color: Color) -> Self

    • Sets the background color of the popup.
    • For Top, Center and Bottom popups.
  • overlayColor(_ color: Color) -> Self

    • Sets the color of the overlay behind the popup.
    • For Top, Center and Bottom popups.
  • tapOutsideToDismissPopup(_ value: Bool) -> Self

    • Enables or disables the dismissal of the popup when touched outside.
    • For Top, Center and Bottom popups.
  • popupTopPadding(_ value: CGFloat) -> Self

    • Sets the top padding of the popup.
    • For Top and Bottom popups.
  • popupBottomPadding(_ value: CGFloat) -> Self

    • Sets the bottom padding of the popup.
    • For Top and Bottom popups.
  • dragThreshold(_ value: CGFloat) -> Self

    • Sets the drag threshold for dismissing the popup or moving to the next drag detent value.
    • For Top and Bottom popups.
  • enableStacking(_ value: Bool) -> Self

    • Enables or disables the visibility of stacked popups.
    • For Top and Bottom popups.
  • enableDragGesture(_ value: Bool) -> Self

    • Enables or disables the drag gesture for interacting with popups.
    • For Top and Bottom popups.

Local

Overview

Allows you to override the global settings for specific popups, providing flexibility for individual customization. The following sections provide an example of use and list the available methods.

Code Example

struct BottomPopupExample: BottomPopup {
    func configurePopup(config: BottomPopupConfig) -> BottomPopupConfig {
        config
            .heightMode(.auto)
            .cornerRadius(44)
            .dragDetents([.fraction(1.2), .fraction(1.4), .large])
    }
    var body: some View {
        Text("Hello Kitty")
    }
}

Available Methods

  • popupHorizontalPadding(_ value: CGFloat) -> Self
    • Sets the horizontal padding of the popup.
    • For Top, Center and Bottom popups.
  • cornerRadius(_ value: CGFloat) -> Self
    • Sets the corner radius of the popup background.
    • For Top, Center and Bottom popups.
  • backgroundColor(_ color: Color) -> Self
    • Sets the background color of the popup.
    • For Top, Center and Bottom popups.
  • overlayColor(_ color: Color) -> Self
    • Sets the color of the overlay behind the popup.
    • For Top, Center and Bottom popups.
  • tapOutsideToDismissPopup(_ value: Bool) -> Self
    • Enables or disables the dismissal of the popup when touched outside.
    • For Top, Center and Bottom popups.
  • popupTopPadding(_ value: CGFloat) -> Self
    • Sets the top padding of the popup.
    • For Top and Bottom popups.
  • popupBottomPadding(_ value: CGFloat) -> Self
    • Sets the bottom padding of the popup.
    • For Top and Bottom popups.
  • ignoreSafeArea(edges: Edge.Set) -> Self
    • Expands the safe area of a popup.
    • For Top and Bottom popups.
  • heightMode(_ value: HeightMode) -> Self
    • Sets the height for the popup.
    • For Top and Bottom popups.
  • dragDetents(_ value: [DragDetent]) -> Self
    • Sets the available detents for the popup.
    • For Top and Bottom popups.
  • enableDragGesture(_ value: Bool) -> Self
    • Enables or disables the drag gesture for interacting with popups.
    • For Top and Bottom popups.

See also