Skip to content
Destructive Actions preview
Rendered from the SwiftUI source on this page.

Destructive Actions

From syxUI — written for both platforms, not translated between them.

An action sheet with a destructive option.

Cards · SwiftUI · iOS 17

  • cards
  • swiftui

The actual source

DestructiveActionSheet.swift
// Destructive Actions · syxUI · https://syxui.dev/components/sheet-action-destructive
// Free in any project. Keep this line and credit syxUI where a person can read it.

import SwiftUI

let shBlue = Color(red: 0.0, green: 0.47, blue: 1.0)
let shRed = Color(red: 0.90, green: 0.24, blue: 0.28)

func shCard<C: View>(_ w: CGFloat, radius: CGFloat = 18, @ViewBuilder _ c: () -> C) -> some View {
    c().frame(width: w).background(Color(.systemBackground), in: RoundedRectangle(cornerRadius: radius, style: .continuous)).overlay(RoundedRectangle(cornerRadius: radius, style: .continuous).stroke(Color.primary.opacity(0.07), lineWidth: 1)).shadow(color: .black.opacity(0.05), radius: 12, y: 5)
}

// Action sheet with destructive
struct DestructiveActionSheet: View {
    var body: some View {
        VStack(spacing: 8) {
            shCard(320) {
                VStack(spacing: 0) {
                    HStack(spacing: 12) { Image(systemName: "arrow.right.square").font(.system(size: 17)).foregroundStyle(shBlue).frame(width: 24); Text("Move to another board").font(.system(size: 16)); Spacer() }.padding(.horizontal, 16).padding(.vertical, 14)
                    Divider()
                    HStack(spacing: 12) { Image(systemName: "trash").font(.system(size: 17)).foregroundStyle(shRed).frame(width: 24); Text("Remove").font(.system(size: 16)).foregroundStyle(shRed); Spacer() }.padding(.horizontal, 16).padding(.vertical, 14)
                }
            }
            shCard(320) { Text("Cancel").font(.system(size: 17, weight: .semibold)).foregroundStyle(shBlue).frame(maxWidth: .infinity).padding(.vertical, 15) }
        }
    }
}
iOS 17 · No dependencies

Dependencies

SwiftUI
No external dependencies

Requires iOS 17