Docs
Cards

Swipe Deck

A card stack you swipe: the top card follows the finger, a glass outcome badge stamps at the threshold and a flick throws it away.

$npx swiftpieces add SwipeDeck
Free · MIT + Commons ClauseiOS 17.0+Liquid Glasscardsswipestackdraggesturespringdecide
Type
SwipeDeck
Files
SwipeDeck.swift
Depends on
Nothing (Apple frameworks only)
Version
2.2.0

Swipeable card stack over Identifiable data. The deck removes the top item from items after each throw.

Notes

  • The deck is the source of truth for nothing: it removes the top item from the bound items array after each throw and reports the direction through onSwipe. Append items to keep the stack going, or watch the array run empty.
  • Directions use SwiftUI's Edge so the file stays self-contained: .trailing (swiped right), .leading (left), .top (up). Down is never committed: a downward drag meets rubber-band resistance and springs back.
  • Commit is decided from predictedEndTranslation, so a flick throws even from a short drag. The horizontal threshold is 40% of the width, the upward one 30% of the height. A .selection tick fires the moment the drag crosses either, and a solid impact fires on the throw.
  • The card flies along its actual vector (drag plus velocity) for 1.6x the deck's larger dimension, leaving at its own speed on each axis, then is removed without a transition. A release short of the threshold returns home at that speed on the elastic settle spring, swinging a little past center before it rests, and a drag the system cancels (a parent scroll, a call) brings it home on the quicker snap spring. The card's speed is the finger's, except while it is pulled down against the rubber band: there it lets go at the band's slower pace, so a release still pulling down never lurches further down before it turns home.
  • The cards beneath rise with the drag, the second card first and each deeper one a little later along it, from 0.95 scale and 16pt lower per step. When a card is thrown, the cards beneath finish rising on follow-through springs, each a beat after the one above, so the next card settles into place with a little give. One more card than visibleCount waits invisibly at the back and fades up as the top card leaves, so nothing pops in.
  • Rotation is 14° per card width, pivoting on the edge opposite your finger: grab the top half and it swings from its base, grab the bottom half and it swings from its top. Catch the card on its way home and it keeps its pivot until the swing has landed, so it never jumps sideways. Reduce Motion drops the rotation, returns home without overshoot and fades the card out in place instead of throwing it, then steps the stack up on a short spring without overshoot. Badges fade in and out where they rest instead of budding, and keep their size instead of swelling and stamping.
  • swipe: is a command binding: set it to a direction to throw programmatically (from buttons, a keyboard shortcut, or a preview loop); the deck resets it to nil. VoiceOver gets "Swipe right", "Swipe left", and "Swipe up" actions on the top card.
  • Give the deck an explicit frame; cards are sized to fill it.
  • Outcome badges are tinted liquid glass. Once the top card is a fifth of the way to a threshold, the badge for that direction (Skip, Keep, Save by default) buds in through the card's edge on the liquid split spring: the card's edge hides it until it emerges, and its glyph and title blur in just after it leaves. Badges rest where they stay in view however far the card travels, even in a full-width deck: Skip and Keep at the top centre, budding in through the top edge from the side the card is heading for, and Save at the bottom centre, rising through the bottom edge the way the card is going, since the top goes off screen first. A badge swells a little toward the threshold under the finger, and stamps on with the success spring's give as the drag crosses it. Turn the card another way and it melts back out the way it came, with no bounce, its tint draining to clear glass, while the new direction's badge buds in past it; let the card come home and it melts away once the card is nearly there. A thrown card takes its badge with it, and the card that rises starts with none. The threshold tick never doubles up with a throw's impact. Cards further down sit in shade and brighten as they rise, and the top card's shadow deepens with the drag.
  • style: (SwipeDeck.Style) sets the three SwipeDeck.Badge values (title, symbol, fill as the glass tint, ink; nil hides one), cornerRadius (which also clips the badges to your card's outline), shadowOpacity, and emptyMessage, a dashed slot drawn when the deck runs out. .plain turns badges and the slot off. VoiceOver actions use the badge titles. All text is semibold.
  • v2.2: the solid badges that faded in over the card became tinted liquid glass that buds in through the card's edge and melts back out. Skip and Keep moved from the top corners to the top centre.

Usage

SwipeDeckExample()
    .preferredColorScheme(.light)

Parameters

ParameterDescription
itemsBound array of cards, top first. Swiped items are removed from the front.
swipeOptional command binding. Set it to .leading, .trailing, or .top to throw the top card programmatically; the deck resets it to nil.
visibleCountHow many cards are drawn in the stack.
styleOutcome badges, stack depth, and the empty slot. .standard shows Skip, Keep, and Save badges on tinted glass.
onSwipeCalled after a card is thrown, with the direction (.leading, .trailing, or .top) and the item.
onTapOptional tap handler for the top card.
cardBuilds one card. Give it its own shape and surface; the deck sizes it to fill the deck's frame.

Install

Pick one. Run it from the folder that contains your .xcodeproj and the files land inside your app.

Terminal

$npx swiftpieces add SwipeDeck

Or ask your coding agent · Claude Code, Cursor or Xcode, once the MCP server is connected

>Add the SwiftPieces "Swipe Deck" piece to my app

Or copy the source above into your app.

New to SwiftUI?If you know React, CSS or Tailwind, SwiftUI is easier to pick up than it looks.Try real app patterns first

Building a whole app? See SwiftPieces Pro →

All cards →

Build it yourself: SwiftUI motion guide · SwiftUI cards guide · SwiftUI animations guide

On this page

SwiftPiecesPro

Build the whole app with one library.

Production-ready screens, whole flows, complete app templates, a Build Kit your agent follows and Pro remixing.

54 screens · 46 patterns · 48 flows · 12 templates · 31 Build Kit skills

Explore Pro