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-stackWhen 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.tsand 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 installso 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.
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
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)}
/>;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
| Prop | Type | Default | Description |
|---|---|---|---|
items | | — | The ordered deck; ids must be unique. |
index? | | — | How many cards have been thrown, from 0 to items.length. Pair with |
defaultIndex? | | | The first position when uncontrolled. |
onIndexChange? | | — | Called with the position someone asked for: a throw, Undo or Reset. |
onThrow? | | — | Called when a card is thrown, with its id and logical direction ( |
onUndo? | | — | Called when Undo brings the last thrown card back. |
onReset? | | — | Called when Reset sends the whole deck back. |
actions? | | | The buttons centred under the stack, in order. Add |
actionLabels? | | | Words on the buttons and in the screen-reader actions. |
actionVariants? | | | Button style, per button. |
actionShape? | | | Corner shape for the action row. |
actionButton? | | | Optional button component for the action row. Receives the label, handler and disabled state. |
layers? | | | How many cards show at once, the top one included. |
swipeable? | | | Let people swipe the top card away. The buttons work either way. |
tilt? | | | Tilt the top card as it is dragged. |
emptyLabel? | | | Message when every card has been thrown. |
empty? | | — | Shown instead of |
disabled? | | | Stops swipes, buttons and screen-reader actions. |
haptics? | | | A tap when a card is thrown, a tick for Undo and Reset. |
motion? | | | Motion for the cards and buttons. |
className? | | — | Classes merged over the root, which holds the stack and the buttons. |
style? | | — | Native style escape hatch for the root. |
testID? | | — | Root identifier. Cards add |
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
startorend, so it reads the same in right-to-left languages. onIndexChange, onUndo and onReset report the rest.
Deck settings
| Prop | Does | Default |
|---|---|---|
| actions | The buttons below the stack, in order: pass, keep, undo, reset | ['pass', 'keep', 'reset'] |
| actionLabels | The button and screen-reader action words | Pass, Keep, Undo, Reset |
| actionVariants | Each button's style | outline |
| actionShape | Corner shape shared by the action buttons | Preset radius |
| actionButton | Custom component for the actions, including the Pro Glass preview controls | SwipeUI Button |
| layers | How many cards show at once | 3 |
| swipeable | Lets people swipe the top card; the buttons work either way | true |
| tilt | Tilts the top card as it is dragged | true |
| haptics | A tap per throw, a tick for Undo and Reset | true |
| emptyLabel / empty | What shows when every card has been thrown | No more cards |
| disabled | Stops swipes, buttons and screen-reader actions | false |
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,listandpressmotion roles, so it follows your app's feel. Passmotionto 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 on | Supported |
|---|---|
| Expo SDK 57 | Yes |
| Expo SDK 58 | Yes |
| React Native CLI (with Expo modules) | Yes |
| Expo Go | Yes |
| iOS | Yes |
| Android | Yes |
This table describes API support and static bundle checks. Native runtime, device accessibility and bare Uniwind compatibility remain pending.