Flip card
Two faces of one card that turn over in 3D, with the flip button centred below the card instead of on it.
npx @swipeui/cli add flip-cardWhen to use it
- Flashcards for learning: a question on the front and the answer on the back.
- A summary that turns over to show its breakdown, such as a Metric card on the front and a Table card on the back.
- A plan or product card that flips to show the fine print or specs.
- Revealing a detail on purpose, such as a gift message or a quiz answer.
When not to use it
- Important information people might miss on the back. Show it up front or use Expandable card.
- Content that needs both sides visible at once for comparison.
- Decorative flips with no real second face; it adds a step without adding value.
- Long text on either side. A sheet or detail screen is easier to read.
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 flip-card- Adds
components/swipeui/card/flip-card.tsx,components/swipeui/card/use-flip-card.tsand 10 shared helpers. - Installs 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
Flip card is a container. front and back take any two cards, and they don't have to be the same kind. Flip card adds only the turn.
The preview above turns the Pro Credit card over to show this. It isn't part of Flip card, and installing it never adds it; pass your own faces in front and back.
import { FlipCard } from '@/components/swipeui/card/flip-card';
import { MetricCard } from '@/components/swipeui/card/metric-card';
import { TableCard } from '@/components/swipeui/card/table-card';
<FlipCard
front={<MetricCard title="Steps this week" value={52140} change="+8%" trend="up" className="min-h-60" />}
back={<TableCard title="This week" rows={week} density="compact" className="min-h-60" />}
/>;Examples
import { useState } from 'react';
import { FlipCard } from '@/components/swipeui/card/flip-card';
import { Card } from '@/components/swipeui/card/card';
import { Button } from '@/components/swipeui/ui/button';
import { Text } from '@/components/swipeui/ui/text';
// Your own control: no built-in button, and a tap on the card flips it too.
const [flipped, setFlipped] = useState(false);
<FlipCard
controls="none"
flipOnPress
flipped={flipped}
onFlippedChange={setFlipped}
front={<Card header={<Text variant="title-3">Capital of Peru?</Text>} />}
back={<Card header={<Text variant="title-3">Lima</Text>} />}
/>;
<Button onPress={() => setFlipped(!flipped)}>{flipped ? 'Hide answer' : 'Reveal answer'}</Button>;API reference
FlipCardProps
| Prop | Type | Default | Description |
|---|---|---|---|
front | | — | The front face: any element, such as a Card, a MetricCard or your own view. It brings its own surface and keeps its own accessibility. |
back | | — | The back face, drawn at the same width as the front. |
flipped? | | — | Shows the back when true. Pair with |
defaultFlipped? | | | The side shown first when uncontrolled. |
onFlippedChange? | | — | Called with the side someone asked for, from the button or a tap on the card. |
controls? | | |
|
flipLabels? | | | The flip button's label on the front and on the back. |
controlVariant? | | | The flip button's style. |
flipOnPress? | | | Also flip when the card itself is tapped. A long press never flips, so a face's own press-and-hold (such as copying a value) still works, and controls on a face keep their own taps. Screen readers use the flip button. |
disabled? | | | Stops the card from flipping and disables the button. |
haptics? | | | A haptic tap when the card is flipped. |
motion? | | | Motion for the turn and the button. |
className? | | — | Classes merged over the root, which holds the card and the button. |
style? | | — | Native style escape hatch for the root. |
testID? | | — | Root identifier; the faces add |
Composition and behavior
- front and back are complete faces: any card or view. Flip card adds no surface or padding, so each face brings its own, such as a Card, a Metric card or a Table card. Only the face you can see is visible to screen readers and touch.
- The flip button sits outside the card, centred below it. controls="none" removes it so you can put your own control anywhere and flip through flipped.
- flipOnPress also flips on a tap. A long press never flips, so a press-and-hold on either face, such as copying a value, still works. Screen readers flip with the button.
- The card turns 180° in 3D on the morph spring and can be reversed mid-turn. Under Reduce Motion the faces cross-fade instead. In right-to-left layouts it turns the other way.
- The card keeps the taller face's height, so flipping never moves the layout.
Flip settings
| Prop | Does | Default |
|---|---|---|
| controls | below centres a flip button under the card; none renders no button | below |
| flipOnPress | A tap on the card flips it too | false |
| flipLabels | The button's words on the front and the back | Show back, Show front |
| controlVariant | The button's style | outline |
| haptics | Plays a haptic tap on each flip | true |
| disabled | Stops all flipping | false |
| motion | The turn's feel; none cross-fades | the app's feel |
Behavior and gestures
- Tap the Show back button under the card and the whole card turns over in 3D; tap Show front to turn it back. The button sits outside the card, so the faces stay clean.
- controls="none" removes the button so you can place your own and flip through flipped. flipOnPress also lets a tap on the card flip it.
- A long press never flips the card, so a press-and-hold on either face (such as copying a value) still works, and buttons on a face keep their own taps.
- The flip can be reversed mid-turn. The card keeps the taller face's height, so flipping never moves the layout.
- Each flip plays a haptic tap; haptics={false} turns it off. A disabled card can't be flipped.
Accessibility
- Only the face you can see is available to screen readers; the hidden face can't be focused or touched.
- The flip button changes its label (Show back or Show front), so people always know what it will do; translate the words with flipLabels.
- A tap on the card is a pointer shortcut only. Screen readers flip with the button, so with controls="none" give them your own control.
- Under Reduce Motion the faces cross-fade instead of turning, which avoids motion discomfort.
- In right-to-left layouts the card turns the other way, toward the reading direction.
Motion
- Uses the
morphandpressmotion roles, so it follows your app's feel. Passmotionto tune this one instance. - The card turns 180 degrees about its vertical axis with perspective on the morph spring, sinking back slightly at mid-turn; the faces swap where both are edge on.
- Bouncier feels let the turn overshoot and settle. Under Reduce Motion, or with the none feel, the faces cross-fade instead.
- The button and the card use the press role for their feedback.
Performance
- The turn animates two transforms on the UI thread; React renders only when the side changes.
- Both faces stay mounted, so keep heavy content such as video off the hidden side.
Notes for AI
- FlipCard is a container: pass any two complete faces, such as a Card, a MetricCard, a TableCard or your own view. Each face brings its own surface; FlipCard adds no surface or padding, only the turn.
- Use flipped with onFlippedChange to control the side, or defaultFlipped for the first side.
- controls="none" hides the built-in button; flipOnPress adds tap-to-flip. A long press never flips.
- Don't hide required information on the back.
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.