# React Native Swipe Cards, Tinder style (Pro)

> A Tinder-style swipe deck for React Native on iOS, Android and the web: cards that tilt as you drag, LIKE and NOPE stamps, fling physics, the cards behind growing into place, round like, nope, super like and undo buttons, a ref to swipe from code, arrow keys on the web and an empty state. No native modules. Part of Patine Pro.

# Swipe deck Pro

`CardStack` is Tinder's deck: drag the top card and it tilts with your finger while **LIKE** or **NOPE** stamps fade in; let go past the line, or fling it, and it flies off; short of it, it springs back. The cards behind grow into place as it leaves. Round buttons under the deck, the arrow keys on the web and `ref.current.swipe()` throw it for you, and **Undo** brings the last card back from the side it left.

It's for dating and matching apps, but just as much for triage: approve or reject expenses, keep or archive photos, learn or skip flashcards, shortlist candidates.

```tsx
import { CardStack, CardStackScrim } from '@patine-ui/pro';
```

```tsx live
import { Image, View } from 'react-native';
import { Text } from 'patine-ui';
import { CardStack, CardStackScrim } from '@patine-ui/pro';

const PEOPLE = [
  { id: '1', name: 'Sofia', age: 27, about: 'Product designer · loves film cameras', photo: 'https://picsum.photos/id/64/600/800', km: 3 },
  { id: '2', name: 'Noah', age: 30, about: 'Climbs, cooks, codes', photo: 'https://picsum.photos/id/91/600/800', km: 8 },
  { id: '3', name: 'Lena', age: 25, about: 'Architect · Sunday markets', photo: 'https://picsum.photos/id/338/600/800', km: 1 },
  { id: '4', name: 'Theo', age: 29, about: 'Jazz piano and bad puns', photo: 'https://picsum.photos/id/1005/600/800', km: 5 },
];

export default function Example() {
  return (
    <View style={{ maxWidth: 380, width: '100%', alignSelf: 'center' }}>
      <CardStack
        data={PEOPLE}
        keyExtractor={(p) => p.id}
        cardLabel={(p) => `${p.name}, ${p.age}, ${p.km} kilometres away`}
        onSwipe={(p, direction) => console.log(direction, p.name)}
        renderCard={(p) => (
          <View style={{ flex: 1 }}>
            <Image source={{ uri: p.photo }} style={{ position: 'absolute', top: 0, right: 0, bottom: 0, left: 0 }} />
            <CardStackScrim />
            <View style={{ position: 'absolute', left: 20, right: 20, bottom: 20, gap: 4 }}>
              <Text size="2xl" weight="semibold" style={{ color: '#fff' }}>
                {p.name} <Text size="xl" style={{ color: '#fff' }}>{p.age}</Text>
              </Text>
              <Text size="sm" style={{ color: 'rgba(255,255,255,0.85)' }}>{p.about} · {p.km} km away</Text>
            </View>
          </View>
        )}
      />
    </View>
  );
}
```

## Example: approve expenses

A manager clears the week's expense claims: swipe right to approve, left to reject, or use the buttons. Turn the stamps into your words with `labels`, limit the `directions`, hide the round buttons with `actions={false}`, and throw cards from your own buttons through the ref.

```tsx live
import { useRef, useState } from 'react';
import { View } from 'react-native';
import { Badge, Button, Text } from 'patine-ui';
import { CardStack } from '@patine-ui/pro';

const EXPENSES = [
  { id: 'e1', who: 'Maya Lindqvist', what: 'Flight to Berlin', amount: '$412.00', category: 'Travel', note: 'Customer visit, Acme GmbH' },
  { id: 'e2', who: 'Leo Brandt', what: 'Team dinner', amount: '$286.40', category: 'Meals', note: '6 people, sprint wrap-up' },
  { id: 'e3', who: 'Ana Souza', what: 'Figma seats', amount: '$135.00', category: 'Software', note: 'Annual, 3 editors' },
];

export default function Example() {
  const deck = useRef(null);
  const [log, setLog] = useState([]);
  return (
    <View style={{ maxWidth: 380, width: '100%', alignSelf: 'center', gap: 14 }}>
      <CardStack
        ref={deck}
        data={EXPENSES}
        height={260}
        actions={false}
        directions={['left', 'right']}
        labels={{ left: 'REJECT', right: 'APPROVE' }}
        keyExtractor={(e) => e.id}
        cardLabel={(e) => `${e.what}, ${e.amount}, from ${e.who}`}
        onSwipe={(e, direction) => setLog((l) => [`${direction === 'right' ? 'Approved' : 'Rejected'} ${e.what}`, ...l])}
        renderCard={(e) => (
          <View style={{ flex: 1, padding: 22, gap: 8, justifyContent: 'flex-end' }}>
            <Badge variant="secondary" style={{ alignSelf: 'flex-start' }}>{e.category}</Badge>
            <Text size="3xl" weight="semibold">{e.amount}</Text>
            <Text weight="medium">{e.what}</Text>
            <Text size="sm" color="textSecondary">{e.who} · {e.note}</Text>
          </View>
        )}
      />
      <View style={{ flexDirection: 'row', gap: 10 }}>
        <Button variant="outline" style={{ flex: 1 }} onPress={() => deck.current?.swipe('left')}>Reject</Button>
        <Button style={{ flex: 1 }} onPress={() => deck.current?.swipe('right')}>Approve</Button>
      </View>
      <Button variant="ghost" size="sm" onPress={() => deck.current?.undo()}>Undo</Button>
      {log.map((line) => (
        <Text key={line} size="sm" color="textSecondary">{line}</Text>
      ))}
    </View>
  );
}
```

## When the deck runs out

The default empty state says "You're all caught up" with an **Undo last** button. Give `renderEmpty` for your own, such as "Widen your search", and `onEnd` to load the next page of cards.

## Accessibility

- The top card is announced with `cardLabel`, and carries screen reader actions for each direction (Like, Nope, Super like), so nobody has to drag. The cards behind are hidden from screen readers.
- The buttons read "Nope", "Super like", "Like" and "Undo", and are 44 and 60 points.
- On the web, focus the deck and use ← (nope), → (like), ↑ (super like) and Backspace (undo).
- With reduce motion on, cards leave and come back without flying.

## Props

| Prop | Type | Default |
| --- | --- | --- |
| `data` | `T[]` | |
| `renderCard` | `(item, { index, top }) => ReactNode` | |
| `keyExtractor` | `(item, index) => string` | |
| `onSwipe` | `(item, direction, index) => void` | |
| `onUndo` | `(item, direction, index) => void` | |
| `onEnd` | `() => void` | |
| `ref` | `{ swipe(direction), undo() }` | |
| `cardLabel` | `(item) => string` | |
| `directions` | `('left' \| 'right' \| 'up')[]` | all three |
| `labels` | `{ left, right, up }` | NOPE, LIKE, SUPER LIKE |
| `actions` | `boolean`: the round buttons | `true` |
| `renderEmpty` | `() => ReactNode` | "You're all caught up" |
| `visibleCount` | `number` | `3` |
| `threshold` | `number`, share of the card | `0.3` |
| `height` | `number` | `480` |
| `style`, `cardStyle` | `ViewStyle` | |

`CardStackScrim` draws a dark fade up from a card's bottom edge, so white text reads over any photo: `height` (`220`), `opacity` (`0.75`).

## Related

- [Stories](./stories): Instagram's stories, the other half of a social app.
- [Swipeable row](./swipeable-row): swipe actions on a list row, free.
- [Carousel](./carousel): cards side by side, free.
