suiss/ui ยท Interaction
Card Stack
A deck of cards the user swipes left or right one at a time, with buttons, undo and an empty state.
Card Stack is an open-source interaction from suiss/ui for React Native, SwiftUI and Jetpack Compose. The @esuiss/ui CLI copies its source into your project, so you own the code.

CardStack shows the top card of data with up to visibleCount cards stacked behind it, each slightly smaller and lower. Dragging the top card sideways moves and tilts it, while the cards behind grow into place.
Releasing past threshold, or flicking faster than 800 points per second, flies the card off in that direction and shows the next one; otherwise it springs back. Use it for one-at-a-time decisions such as keep or skip.
Installation
- Install the following dependencies:
-
Copy the animated view into
components/ui/animated-view.tsx:
- Copy the primitives it uses into
components/primitives:
- Copy and paste the following code into
components/interactions/card-stack.tsx:
- Update the import paths to match your project setup.
- Install the following dependencies:
-
Copy the animated view into
components/ui/animated-view.tsx:
- Copy the primitives it uses into
components/primitives:
- Copy and paste the following code into
components/interactions/card-stack.tsx:
- Update the import paths to match your project setup.
- Install the following dependencies:
-
Copy the animated view into
components/ui/animated-view.tsx:
- Copy the primitives it uses into
components/primitives:
- Copy and paste the following code into
components/interactions/card-stack.tsx:
- Update the import paths to match your project setup.
-
Target iOS 17 or later.
-
Add the Swift package to your app:
- Copy the theme files every view uses:
- Copy the source and every file it uses:
- Add the files to your app target.
- Apply the Compose compiler plugin, enable Compose, set
compileSdkto 37 or higher andminSdkto 24 or higher, and add the dependencies:
- Copy the theme files every view uses:
- Copy the source and every file it uses:
- Update the
com.esuiss.uipackage names to match your project.
Usage
Examples
Mid swipe
A static frame of the top card dragged to the right.

This code uses Tailwind classes that need Uniwind or NativeWind. With StyleSheet, pass the same values through the style props.
Empty
An empty deck showing CardStackEmpty.

Disabled
Turns off swiping and the buttons with disabled.

Accessibility
- The top card has
Swipe leftandSwipe rightaccessibility actions. - Cards behind the top card are hidden from screen readers.
- Swipe buttons are labelled
Swipe leftandSwipe right, and undo is labelledUndo, unless you passaccessibilityLabel.
API Reference
CardStack
The root that renders the deck and handles the drag gesture.
| Prop | Type | Default |
|---|---|---|
data | readonly T[] | Required |
renderItem | (item: T, index: number) => React.ReactNode | Required |
keyExtractor | (item: T, index: number) => string | - |
onSwipe | (direction: CardStackDirection, item: T, index: number) => void | - |
onUndo | (item: T, index: number) => void | - |
threshold | number | 120 |
visibleCount | number | 3 |
disabled | boolean | false |
itemAccessibilityLabel | (item: T, index: number) => string | - |
deckClassName | string | - |
Also accepts the props of ViewProps.
Pass data and renderItem, and add children below the deck: CardStackActions with CardStackSwipeButtons and a CardStackUndo, and a CardStackEmpty shown once every card is swiped. onSwipe is called with the direction, item and index after a card leaves. keyExtractor defaults to the card's position. threshold is the drag distance that commits a swipe, and visibleCount is the number of cards stacked behind the top card. disabled turns off the gesture and the swipe buttons. itemAccessibilityLabel returns the label for the top card. The deck area is h-96 by default; change it with deckClassName.
Undo brings back the last card from the side it left and calls onUndo with the item and index. useCardStack exposes index, count, remaining, canUndo, swipe and undo for custom controls. The CardStackDirection type is exported. A medium impact haptic plays when a card is swiped by gesture, button or accessibility action, if the app provides an adapter through HapticsProvider. Fly-out and spring animations respect the system reduce motion setting.
CardStackEmpty
A dashed placeholder shown when no cards remain.
Also accepts the props of ViewProps, React.RefAttributes<View>.
CardStackActions
A centered row for the buttons.
Also accepts the props of ViewProps, React.RefAttributes<View>.
CardStackSwipeButton
A round button that swipes the top card left or right.
| Prop | Type | Default |
|---|---|---|
direction | CardStackDirection | Required |
Also accepts the props of React.ComponentProps<typeof Button>.
left shows an X icon and right shows a heart icon.
CardStackUndo
A button that restores the last swiped card.
Also accepts the props of React.ComponentProps<typeof Button>.
CardStackDirection
Values: .left, .right.
CardStackController
Takes no parameters.
| Property | Type |
|---|---|
index | Int |
history | [CardStackDirection] |
canSwipe | Bool |
canUndo | Bool |
CardStackController.swipe
| Parameter | Type | Default |
|---|---|---|
_ย direction | CardStackDirection: .left | .right | - |
CardStackController.undo
Takes no parameters.
CardStackController.reset
Takes no parameters.
CardStack
The root that renders the deck and handles the drag gesture.
| Parameter | Type | Default |
|---|---|---|
_ย items | [Item] | - |
controller | CardStackController | - |
visibleCount | Int | 3 |
onSwipe | ((CardStackDirection, Item) -> Void)? | nil |
onUndo | ((Item) -> Void)? | nil |
card | (Item) -> Card | - |
CardStackAction
Values: .swipeLeft, .swipeRight, .undo.
CardStackButton
| Parameter | Type | Default |
|---|---|---|
_ย action | CardStackAction: .swipeLeft | .swipeRight | .undo | - |
controller | CardStackController | - |
size | VariantButtonStyle.Size | .iconXl |
CardStackDirection
Values: Left, Right.
CardStackState
| Property | Type |
|---|---|
canUndo | Boolean |
isEmpty | Boolean |
progress | Float |
CardStackState.swipe
| Parameter | Type | Default |
|---|---|---|
direction | CardStackDirection: Left | Right | - |
CardStackState.undo
Takes no parameters.
rememberCardStackState
| Parameter | Type | Default |
|---|---|---|
initialIndex | Int | 0 |
Returns CardStackState.
CardStack
The root that renders the deck and handles the drag gesture.
| Parameter | Type | Default |
|---|---|---|
items | List<T> | - |
onSwipe | (CardStackDirection, T) -> Unit | - |
modifier | Modifier | Modifier |
state | CardStackState | rememberCardStackState() |
key | ((T) -> Any)? | null |
visibleCount | Int | 3 |
enabled | Boolean | true |
onUndo | ((CardStackDirection, T) -> Unit)? | null |
empty | @Composable () -> Unit | {} |
content | @Composable (T) -> Unit | - |



