Add Swipe Actions To SwiftUI Lazy Stacks

Your draft queue uses a ScrollView and LazyVStack. The cards have generous spacing, multiline summaries, and room for an attachment preview. Then someone asks for swipe to delete.

That used to be a reason to reconsider the container or maintain a custom gesture implementation. The WWDC26 SwiftUI additions give this screen a native path: swipe actions work outside List, with swipeActionsContainer() coordinating the surrounding interface. Apple demonstrates the change in What’s new in SwiftUI.

The interesting part is what happens after someone swipes. A row can move while a confirmation dialog is open. Another device can remove the draft. A long swipe can accidentally perform an action you intended to confirm. And someone using a keyboard still needs a way to reach the same commands.

Let’s build a small draft queue around those cases. These APIs were introduced at WWDC26 for iOS 27. September 27 review: the complete queue, row, and item-bound confirmation dialog below type-check in Swift 6 mode with the released Xcode 27 / iOS 27 SDK. The gesture and accessibility checks at the end still belong in your app’s device testing.

Coordinate actions at the scroll view

Apply swipeActions to the individual card, then put swipeActionsContainer() on the containing scroll view:

ScrollView {
    LazyVStack(spacing: 12) {
        ForEach(drafts) { draft in
            DraftCard(
                draft: draft,
                togglePinned: { togglePinned(draft.id) },
                requestDeletion: { requestDeletion(draft) }
            )
            .swipeActions(edge: .trailing, allowsFullSwipe: false) {
                Button("Delete…", systemImage: "trash") {
                    requestDeletion(draft)
                }
                .tint(.red)
            }
        }
    }
    .padding()
}
.swipeActionsContainer()

The container modifier manages which row has revealed actions. Opening another row closes the previous one; scrolling or tapping outside the active row dismisses its actions. List already supplies that coordination.

Place one coordinator around the queue. Attaching a separate coordinator to each card would describe separate groups when the interaction you want spans the whole feed.

There is no app-owned horizontal offset here. The code only decides which commands each draft supports. Keep existing vertical scrolling behavior while checking whether old gesture modifiers are still needed; an inherited highPriorityGesture can be an easy thing to overlook during a migration.

This article focuses on row actions. For container performance, see Fix SwiftUI Lazy Stack Jank Before You Switch To List. For moving items, see Build Reorderable Drag And Drop In SwiftUI.

Give each draft an identity that survives edits

Use the draft’s stored identifier for rendering and mutation:

import SwiftUI

struct Draft: Identifiable {
    let id: UUID
    var title: String
    var summary: String
    var isPinned = false
}

struct PendingDraftDeletion {
    let id: Draft.ID
    let title: String
}

PendingDraftDeletion is a small snapshot of the user’s request. Its identifier answers which record to remove. Its title supplies the dialog text without requiring the card to remain alive.

In an app with persistence, restore Draft.id from storage. Generate it when creating a draft, then save it with that record. A computed property that returns UUID() gives the same draft a different identity every time it is read.

An array index is also the wrong deletion target. Imagine opening a confirmation for the third card, then receiving a new card at the beginning of the queue. The original index now points to a different draft. Resolve the saved identifier against the current data when executing the command.

Keep the deletion request above the cards

Here is the screen’s state and command handling. The example owns a local array so the interaction is easy to inspect. Persistence belongs behind the same commands in a larger app.

@available(iOS 27.0, *)
struct DraftQueueScreen: View {
    @State private var drafts: [Draft] = [
        Draft(
            id: UUID(),
            title: "Weekend field notes",
            summary: "Photos and observations from the trail."
        ),
        Draft(
            id: UUID(),
            title: "Release announcement",
            summary: "A first pass at the next app update."
        ),
    ]
    @State private var pendingDeletion: PendingDraftDeletion?

    var body: some View {
        NavigationStack {
            queue
                .navigationTitle("Drafts")
        }
        .confirmationDialog(
            Text("Delete this draft?"),
            item: $pendingDeletion,
            titleVisibility: .visible
        ) { request in
            Button("Delete Draft", role: .destructive) {
                deleteConfirmed(request.id)
            }
            Button("Cancel", role: .cancel) {}
        } message: { request in
            Text("“\(request.title)” will be permanently deleted.")
        }
    }

    private var queue: some View {
        ScrollView {
            LazyVStack(spacing: 12) {
                ForEach(drafts) { draft in
                    DraftCard(
                        draft: draft,
                        togglePinned: { togglePinned(draft.id) },
                        requestDeletion: { requestDeletion(draft) }
                    )
                    .swipeActions(
                        edge: .trailing,
                        allowsFullSwipe: false
                    ) {
                        Button("Delete…", systemImage: "trash") {
                            requestDeletion(draft)
                        }
                        .tint(.red)
                    }
                    .swipeActions(
                        edge: .leading,
                        allowsFullSwipe: false
                    ) {
                        Button(
                            draft.isPinned ? "Unpin" : "Pin",
                            systemImage: draft.isPinned ? "pin.slash" : "pin"
                        ) {
                            togglePinned(draft.id)
                        }
                        .tint(.orange)
                    }
                }
            }
            .padding()
        }
        .swipeActionsContainer()
        .overlay {
            if drafts.isEmpty {
                ContentUnavailableView(
                    "No Drafts",
                    systemImage: "doc.text",
                    description: Text("New drafts will appear here.")
                )
            }
        }
    }

    private func requestDeletion(_ draft: Draft) {
        pendingDeletion = PendingDraftDeletion(
            id: draft.id,
            title: draft.title
        )
    }

    private func togglePinned(_ id: Draft.ID) {
        guard let index = drafts.firstIndex(where: { $0.id == id }) else {
            return
        }
        drafts[index].isPinned.toggle()
    }

    private func deleteConfirmed(_ id: Draft.ID) {
        pendingDeletion = nil
        guard let index = drafts.firstIndex(where: { $0.id == id }) else {
            return
        }
        drafts.remove(at: index)
    }
}

The new item-bound confirmation dialog uses an optional binding to drive presentation and passes the value into its content closures. That makes the pending request the source of truth for both the prompt and its target.

Attach the dialog once at the screen level. A single screen-owned request is easier to reason about than a Boolean repeated on every lazily created card. The final action uses the request passed into the dialog closure, so it doesn’t need a separate “currently selected row” lookup.

The snapshot deliberately preserves the title shown when deletion was requested. The operation still checks the current collection. If that draft has already disappeared, the function safely returns. A store-backed implementation can report that outcome if it matters to the workflow.

For a collaborative editor, identity alone may be insufficient: someone could add new content after the prompt appeared. If deleting that newer content would violate the user’s expectation, include a revision in the pending request and ask the store to reject a mismatched revision. Never derive permission to delete from a row’s visibility.

Make full-swipe behavior a product decision

In this queue, deleting a draft is permanent. The swipe button requests confirmation; only the dialog’s Delete Draft button has a destructive role and actually mutates the array. Keeping those operations separate also makes Cancel straightforward: the draft never left the collection.

Set allowsFullSwipe: false explicitly. Apple’s swipe action documentation says the default permits a full swipe to perform the first action. Button order therefore changes behavior, not just appearance.

An archive operation with a dependable undo path might reasonably support full swipe. That requires an archive command, recoverable storage, and undo behavior the user can discover. Replacing false with true doesn’t supply those pieces.

For remote deletion, keep the record visible or show a pending state until your chosen persistence strategy succeeds. If the request fails, preserve the draft and offer retry. Make repeated requests for the same identifier safe in the store; disabling one button doesn’t prevent another entry point from issuing the command.

Provide a visible way to reach the commands

A swipe is convenient when you know it exists. The card also exposes a labeled menu:

private struct DraftCard: View {
    let draft: Draft
    let togglePinned: () -> Void
    let requestDeletion: () -> Void

    var body: some View {
        HStack(alignment: .top, spacing: 12) {
            VStack(alignment: .leading, spacing: 6) {
                Text(draft.title)
                    .font(.headline)

                Text(draft.summary)
                    .font(.subheadline)
                    .foregroundStyle(.secondary)

                if draft.isPinned {
                    Label("Pinned", systemImage: "pin.fill")
                        .font(.caption)
                }
            }
            .frame(maxWidth: .infinity, alignment: .leading)

            Menu {
                Button(
                    draft.isPinned ? "Unpin" : "Pin",
                    systemImage: draft.isPinned ? "pin.slash" : "pin"
                ) {
                    togglePinned()
                }
                Button("Delete…", systemImage: "trash") {
                    requestDeletion()
                }
            } label: {
                Image(systemName: "ellipsis")
                    .frame(width: 44, height: 44)
                    .contentShape(Rectangle())
            }
            .accessibilityLabel(Text("Actions for \(draft.title)"))
        }
        .padding()
        .background(.quaternary, in: RoundedRectangle(cornerRadius: 16))
    }
}

The menu and swipe buttons call the same closures, so they share the same confirmation and identity rules. No alternate deletion implementation can drift away from the main path.

Apple’s accessibility guidance recommends onscreen alternatives to gestures. Here, a person can discover the ellipsis button, hear which draft it belongs to, and invoke a normal menu command.

The card also avoids a fixed height and shows a text label for its pinned state. Test the menu with VoiceOver and keyboard navigation. Keep it as a separate accessible control; combining the entire card into a single accessibility element can change how its children are exposed.

Observe presentation only when it changes the experience

The swipe action overload with onPresentationChanged reports whether the actions are visible. For example, a media draft card could pause its own animated thumbnail while its commands are open:

@available(iOS 27.0, *)
struct PreviewRow<Preview: View>: View {
    @State private var actionsVisible = false
    let requestDeletion: () -> Void
    let preview: (Bool) -> Preview

    var body: some View {
        preview(!actionsVisible)
            .swipeActions(edge: .trailing, allowsFullSwipe: false) {
                Button("Delete…", systemImage: "trash", action: requestDeletion)
            } onPresentationChanged: { isPresented in
                actionsVisible = isPresented
            }
    }
}

The caller supplies a preview closure whose Boolean controls animation, plus the deletion action. The row retains presentation state for that preview’s lifetime.

DraftPreview represents your existing preview view. The callback is a visibility signal, not a deletion event or a binding for opening another row. Keep durable state changes in the buttons’ command closures. The queue above doesn’t need to track this signal at all.

Test the interaction while the data changes

A useful manual pass should include more than revealing one Delete button:

  • Reveal one card, then another. Scroll and tap outside the active card.
  • Request deletion, cancel, then delete a different draft. Confirm that only the named draft disappears.
  • Insert or reorder records while a dialog is open. The deletion target must remain the saved identifier.
  • Remove the pending record through another store update, then confirm. No neighboring record should disappear.
  • Try narrow widths, large text, right-to-left layout, VoiceOver, and the visible menu with a keyboard.
  • If cards also support drag and drop, test reordering and swiping together, including diagonal movements and long presses.

For older deployment targets, gate the new screen or modifier path with availability checks. A List implementation can retain native swipe actions on earlier systems; a custom card layout can retain the visible menu. Keep the underlying commands shared and use the older Boolean-plus-presenting: confirmation API in that fallback.

The payoff is a custom queue with familiar system interactions and a small amount of app-owned state. SwiftUI coordinates the revealed actions. Your app decides which record a command targets, when deletion is committed, and how someone reaches that command without swiping.