Skip to main content

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.

import { CardStack, CardStackScrim } from '@patine-ui/pro';
Loading…
<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.

Loading…
<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​

PropTypeDefault
dataT[]
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
actionsboolean: the round buttonstrue
renderEmpty() => ReactNode"You're all caught up"
visibleCountnumber3
thresholdnumber, share of the card0.3
heightnumber480
style, cardStyleViewStyle

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

  • Stories: Instagram's stories, the other half of a social app.
  • Swipeable row: swipe actions on a list row, free.
  • Carousel: cards side by side, free.