Skip to content

Alert - iOS ​

Alerts show high-signal messages meant to be noticed and prompting users.

AndroidreleasedElementsreleasediOSreleasedReactreleasedReact 19releasedVuereleased

iOS ​

Syntax ​

swift
Warp.Alert(
    style: Warp.AlertStyle,
    title: String,
    subtitle: String,
    link: ButtonConstructor? = nil,
    primaryButton: ButtonConstructor? = nil,
    secondaryButton: ButtonConstructor? = nil
)

ButtonConstructor is a typealias for (title: String, action: () -> Void).

swift
Warp.Alert(
    style: .critical,
    title: "This is the critical variant of the alert component",
    subtitle: "With an additional description"
)

There are four types of alert styles:

swift
enum Warp.AlertStyle {
    /// Used to display messages that provide the user with general information.
    case info
    /// Used to indicate that something is not working as expected or might need attention.
    case warning
    /// Used to indicate a severe problem or error that requires immediate attention.
    case critical
    /// Used to indicate that an action was successful or that a task was completed successfully.
    case success
}

It is possible to add an optional link text, primary button and a secondary button or all together.

swift
Warp.Alert(
    style: .critical,
    title: "This is the critical variant of the alert component",
    subtitle: "With an additional description",
    link: (title: "Link to more information", action: {}),
    primaryButton: (title: "Button", action: {}),
    secondaryButton: (title: "Button", action: {})
)

Legacy support ​

By default all Warp components return a SwiftUI View but there is always a UIKit UIView available to use also.

swift
Warp.Alert(
    style: .critical,
    title: "This is the critical variant of the alert component",
    subtitle: "With an additional description"
).uiView

Parameters ​

Required props ​

NameTypeDefaultDescription
styleWarp.AlertStyleThe visual style of the alert, which dictates its colors, icons, and overall appearance. Use one of the predefined AlertStyle values: .info, .warning, .critical, or .success.
titleStringThe primary text displayed at the top of the alert, used to capture the user's attention.
subtitleStringAdditional information displayed below the title, used to provide further context to the alert.

Optional Props ​

NameTypeDefaultDescription
link(title: String, action: () -> Void)?nilAn optional tuple containing the title and action for a clickable link that appears below the subtitle.
primaryButton(title: String, action: () -> Void)?nilAn optional tuple containing the title and action for a primary button.
secondaryButton(title: String, action: () -> Void)?nilAn optional tuple containing the title and action for a secondary button.

Alert dialog ​

An alert dialog presents critical information and requires an explicit response from the user, using the native iOS alert mechanism.

Syntax ​

Apply the .warpAlert() modifier to any view. The dialog is presented when isPresented becomes true.

swift
// Without embedded content
someView
    .warpAlert(
        title: String,
        message: String? = nil,
        actions: [Warp.AlertDialog.Action],
        isPresented: Binding<Bool>
    )

// With embedded content (e.g. TextField)
someView
    .warpAlert(
        title: String,
        message: String? = nil,
        actions: [Warp.AlertDialog.Action],
        isPresented: Binding<Bool>
    ) {
        // SwiftUI views rendered above the action buttons
    }

Basic usage ​

swift
Button("Delete account") {
    showDeleteAlert = true
}
.warpAlert(
    title: "Delete account?",
    message: "This action cannot be undone. All your data will be permanently removed.",
    actions: [
        Warp.AlertDialog.Action(title: "Delete", style: .destructive) { deleteAccount() },
        Warp.AlertDialog.Action(title: "Cancel", style: .cancel) { }
    ],
    isPresented: $showDeleteAlert
)

With embedded content ​

Use the content trailing closure to embed input controls (e.g. TextField, SecureField) above the action buttons. This is appropriate for rename flows, PIN entry, or short confirmation phrases.

swift
Button("Rename item") {
    showRenameAlert = true
}
.warpAlert(
    title: "Rename item",
    actions: [
        Warp.AlertDialog.Action(title: "Save") { saveNewName() },
        Warp.AlertDialog.Action(title: "Cancel", style: .cancel) { }
    ],
    isPresented: $showRenameAlert
) {
    TextField("Name", text: $newName)
}

Action styles ​

swift
enum Warp.AlertDialog.Action.Style {
    /// A standard action button.
    case `default`
    /// A destructive action, displayed in red.
    case destructive
    /// A cancel action, displayed prominently by the system.
    case cancel
}

Always include a .cancel action. Without it, users have no safe exit from the dialog.

Parameters ​

Modifier props ​

NameTypeDefaultDescription
titleStringThe title displayed at the top of the dialog.
messageString?nilOptional message displayed below the title.
actions[Warp.AlertDialog.Action]The actions to display as buttons.
isPresentedBinding<Bool>Controls the dialog's visibility.
content@ViewBuilderEmptyViewOptional SwiftUI views (e.g. TextField) rendered above the action buttons.

Warp.AlertDialog.Action ​

NameTypeDefaultDescription
titleStringThe button label. Use a verb ("Delete", "Save", "Cancel").
styleStyle.defaultVisual style. Use .destructive for irreversible actions, .cancel for the dismiss action.
handler() -> VoidClosure executed when the action is tapped.

Questions? ​

Feel free to ask any questions on usage in the Warp DS Slack channel: #warp-design-system