SwipeUI

Card stack

A swipeable stack of cards with three layers showing, Pass, Keep and Reset centred below, and a deck that springs back with a stagger.

npx @swipeui/cli add card-stack
Variant
Preset
Material
Scheme
Feel
Real free component with a browser animation bridge. Native motion, haptics and materials need a device.

When to use it

  • Swipe-to-decide flows: matching, triaging a reading list or reviewing flashcards one at a time.
  • A deck of any cards people flick through: each item's content can be a different card, such as an Info card, a Metric card or your own view.
  • Recommendations or onboarding choices where people keep or pass on one suggestion at a time.
  • Any swipe interaction that must also work without swiping, thanks to the buttons below and screen-reader actions.

When not to use it

  • Browsing many items side by side. Use a list, or Carousel for horizontal paging.
  • Endless feeds; the deck is designed for a bounded set with a clear end.
  • Removing rows from a list. Swipe actions on a List row fit that better.
  • A single choice between two options. Use buttons or Segmented control.

Installation

Run this from your app's root. If SwipeUI isn't set up yet, run npx @swipeui/cli init first; it sets up Uniwind, the theme tokens and the cn helper.

npx @swipeui/cli add card-stack
  • Adds components/swipeui/card/card-stack.tsx, components/swipeui/card/use-card-stack.ts and 10 shared helpers.
  • Installs react-native-gesture-handler, react-native-reanimated, react-native-worklets, uniwind, clsx, tailwind-merge, expo-haptics, class-variance-authority. In Expo apps it uses npx expo install so versions match your SDK.

Usage

Card stack is a container. Each item's content can be any card, and different cards can share one deck. The stack adds only the layers, the swipe and the motion.

The preview above deals the Pro Credit cards to show this. They aren't part of Card stack, and installing it never adds them; pass your own cards in items.

app/explore.tsx
import { CardStack } from '@/components/swipeui/card/card-stack';
import { InfoCard } from '@/components/swipeui/card/info-card';
import { MetricCard } from '@/components/swipeui/card/metric-card';
import { TableCard } from '@/components/swipeui/card/table-card';

<CardStack
  items={[
    {
      id: 'walks',
      label: 'Mountain walks',
      content: <InfoCard title="Mountain walks" description="A quiet route above the valley." className="min-h-56" />,
    },
    {
      id: 'steps',
      label: 'Steps today',
      content: <MetricCard title="Steps today" value={8432} change="+12%" trend="up" className="min-h-56" />,
    },
    {
      id: 'river',
      label: 'River path',
      content: <TableCard title="River path" rows={route} className="min-h-56" />,
    },
  ]}
  onThrow={(id, direction) => save(id, direction === 'end')}
/>;

Examples

app/discover.tsx
import { CardStack } from '@/components/swipeui/card/card-stack';

// Undo steps back one card at a time; Reset sends the whole deck back.
<CardStack
  items={routes}
  actions={['pass', 'keep', 'undo', 'reset']}
  actionLabels={{ pass: 'Skip', keep: 'Save' }}
  actionVariants={{ keep: 'default' }}
  onUndo={(id) => unsave(id)}
/>;
app/review.tsx
import { CardStack } from '@/components/swipeui/card/card-stack';

// Buttons only: no swiping, no tilt, and your own empty state.
<CardStack items={cards} swipeable={false} tilt={false} empty={<AllDone />} />;

Preview the deck

Swipe and Review includes Pass, Keep, Undo and Reset. Empty Deck starts with the empty-state outline and can reset to the same deck.

API reference

CardStackProps

PropTypeDefaultDescription
itemsreadonly CardStackItem[]—

The ordered deck; ids must be unique.

index?number—

How many cards have been thrown, from 0 to items.length. Pair with onIndexChange.

defaultIndex?number0

The first position when uncontrolled.

onIndexChange?((index: number) => void)—

Called with the position someone asked for: a throw, Undo or Reset.

onThrow?((id: string, direction: CardStackDirection) => void)—

Called when a card is thrown, with its id and logical direction (start passes, end keeps).

onUndo?((id: string) => void)—

Called when Undo brings the last thrown card back.

onReset?(() => void)—

Called when Reset sends the whole deck back.

actions?readonly CardStackAction[]['pass', 'keep', 'reset']

The buttons centred under the stack, in order. Add 'undo' to step back one card; pass [] for no buttons.

actionLabels?Partial<CardStackActionLabels>CARD_STACK_LABELS

Words on the buttons and in the screen-reader actions.

actionVariants?Partial<Record<CardStackAction, ButtonVariant>>'outline' for every button

Button style, per button.

actionShape?ButtonShape'preset'

Corner shape for the action row.

actionButton?ComponentType<ButtonProps>Button

Optional button component for the action row. Receives the label, handler and disabled state.

layers?number3

How many cards show at once, the top one included.

swipeable?booleantrue

Let people swipe the top card away. The buttons work either way.

tilt?booleantrue

Tilt the top card as it is dragged.

emptyLabel?string'No more cards'

Message when every card has been thrown.

empty?ReactNode—

Shown instead of emptyLabel when every card has been thrown.

disabled?booleanfalse

Stops swipes, buttons and screen-reader actions.

haptics?booleantrue

A tap when a card is thrown, a tick for Undo and Reset.

motion?MotionOverridethe app's feel (smooth without a provider)

Motion for the cards and buttons.

className?string—

Classes merged over the root, which holds the stack and the buttons.

style?StyleProp<ViewStyle>—

Native style escape hatch for the root.

testID?string—

Root identifier. Cards add -card-<id>, buttons -pass, -keep, -undo and -reset, and the top card's swipe is -pan.

Composition and behavior

  • items is the ordered deck. Each item has an id, a label for screen readers and its content: any whole card or view, such as an Info card, a Metric card or your own. The stack adds no surface.
  • The top card sets the deck's height, so give the cards in one deck similar heights (a shared min-h-* class works) and the layers line up.
  • Three cards show at once (layers). Each layer down is a little smaller and peeks out lower, and the next card rises as you drag the top one.
  • Drag the top card sideways and let go past a quarter of the width, or flick, to throw it: toward the end keeps it, toward the start passes. Mostly vertical drags are left to the page.
  • The buttons sit centred below the stack: Pass, Keep and Reset by default. Add 'undo' to actions to step back one card at a time, or pass [] for none.
  • Reset springs the whole deck back, deepest card first. Undo and Reset bring cards back in from the side they were thrown to.
  • A long press is never a throw, so a press-and-hold inside a card, such as copying a value, still works.
  • onThrow reports each decision as start or end, so it reads the same in right-to-left languages. onIndexChange, onUndo and onReset report the rest.

Deck settings

PropDoesDefault
actionsThe buttons below the stack, in order: pass, keep, undo, reset['pass', 'keep', 'reset']
actionLabelsThe button and screen-reader action wordsPass, Keep, Undo, Reset
actionVariantsEach button's styleoutline
actionShapeCorner shape shared by the action buttonsPreset radius
actionButtonCustom component for the actions, including the Pro Glass preview controlsSwipeUI Button
layersHow many cards show at once3
swipeableLets people swipe the top card; the buttons work either waytrue
tiltTilts the top card as it is draggedtrue
hapticsA tap per throw, a tick for Undo and Resettrue
emptyLabel / emptyWhat shows when every card has been thrownNo more cards
disabledStops swipes, buttons and screen-reader actionsfalse

Behavior and gestures

  • Use actionButton to supply a themed action component. The stack still manages each action's handler and availability.
  • Drag the top card sideways and it follows your finger, tilting up to about 12 degrees, while the card beneath rises to take its place.
  • Let go past a quarter of the deck's width, or flick, and the card flies off that way; let go earlier and it springs back. Mostly vertical drags are left to the page.
  • Pass, Keep and Reset sit centred below the stack; add Undo with actions to step back one card at a time, or pass [] for no buttons. Reset springs the whole deck back, deepest card first.
  • Undo and Reset bring cards back from the side they were thrown to. Three cards show at once by default; layers changes that.
  • Each throw plays a haptic tap and Undo and Reset a lighter tick. swipeable={false} leaves only the buttons; tilt={false} keeps the card upright.
  • A long press never throws, so a press-and-hold inside a card (such as copying a value) still works.

Accessibility

  • The top card is one focus stop announced by its label; the layers beneath can't be focused or touched.
  • Screen readers get Pass and Keep as actions on the top card, so the deck works with no buttons and no swiping; the buttons are real buttons too.
  • The empty message is a polite live region, so screen readers announce it when the last card goes.
  • In right-to-left layouts, directions are reported as start and end, so swiping toward the reading direction means the same thing in every language.
  • Translate the button and action words with actionLabels.

Motion

  • Uses the drag, layout, list and press motion roles, so it follows your app's feel. Pass motion to tune this one instance.
  • The top card tracks the finger, then flies off or returns on the drag spring with the speed of the flick.
  • Layers move up on the layout spring; the next layer rises with the drag, so the deck never jumps when a card goes.
  • Reset and Undo fly cards back in from the side they left; Reset staggers them on the list role, deepest first.
  • Under Reduce Motion the card still follows the finger but doesn't tilt, and every move is instant.

Performance

  • Dragging runs on the UI thread with Gesture Handler and Reanimated; React renders when a card is thrown, undone or reset.
  • Only the visible layers and cards still flying off are rendered.

Notes for AI

  • Give every item a unique id and a label; the deck throws an error on duplicate ids.
  • CardStack is a container: each item's content is a whole card of your choice, such as <InfoCard />, <MetricCard />, a Card or your own view. The stack adds no surface; it only stacks, swipes and animates.
  • Give the cards in one deck similar heights (for example a shared min-h class); the top card sets the deck's height.
  • Use onThrow to record the decision for each id; direction is start (pass) or end (keep), not left or right.
  • actions defaults to ['pass', 'keep', 'reset']; add 'undo' to step back. onUndo and onReset report those.
  • Use index with onIndexChange to control the position, or defaultIndex to let the deck manage it.

Compatibility

Runs onSupported
Expo SDK 57Yes
Expo SDK 58Yes
React Native CLI (with Expo modules)Yes
Expo GoYes
iOSYes
AndroidYes

This table describes API support and static bundle checks. Native runtime, device accessibility and bare Uniwind compatibility remain pending.

Related items