Card
A token-based surface with media, header, body and independent footer slots.
npx @swipeui/cli add cardWhen to use it
- A home or discovery feed where each place, plan or story gets its own tile with a title, a picture and a line of detail.
- A tile that opens a detail screen when tapped, with separate Save or Share buttons underneath.
- Grouping a few related facts, such as an order summary or a profile section, so they read as one unit.
- Mixing emphasis on one screen: an elevated card for the featured item, outline or filled cards for quieter groups.
- A starting point for your own specialised cards; most SwipeUI cards are built on top of it.
When not to use it
- Long lists of similar records such as messages, contacts or settings rows. List row is denser and easier to scan.
- A single tappable control with nothing else around it. Use Button, or Pressable for a custom shape.
- Content that opens in place. Expandable card handles the open and closed states for you.
- Edge-to-edge artwork on its own. Card media reserves the right shape and handles loading and failures.
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- Adds
components/swipeui/card/card.tsxand 5 shared helpers. - Installs class-variance-authority, react-native-reanimated, react-native-worklets, uniwind, clsx, tailwind-merge, expo-haptics. In Expo apps it uses
npx expo installso versions match your SDK.
Usage
import { Card } from '@/components/swipeui/card/card';
<Card header={<Text>Mountain walks</Text>}>
<Text>A quiet route above the valley.</Text>
</Card>;API reference
CardProps
| Prop | Type | Default | Description |
|---|---|---|---|
header? | | — | Heading content; keep interactive controls in the footer. |
media? | | — | Edge-to-edge media; supply its aspect ratio and accessible description. |
children? | | — | Main content; keep interactive controls in the footer when pressable. |
footer? | | — | Independent actions, outside the card's primary press target. |
variant? | | | Surface treatment. |
disabled? | | | Prevent primary activation; footer controls manage their own disabled state. |
haptics? | | | Primary press feedback. |
motion? | | | Shared press character. |
accessibilityHint? | | — | Describes the result of the primary action. |
className? | | — | Classes merged over the surface. |
style? | | — | Native surface layout escape hatch. |
testID? | | — | Root identifier; primary target appends -press. |
onPress? | | — | Primary card action. Omit for a non-interactive surface. |
accessibilityLabel? | | — | Required summary of the primary card content. Optional surface description. |
Composition and behavior
- media sits edge to edge at the top. Give it a fixed shape, for example with Card media, so the layout doesn't jump while images load.
- header and children hold the title and body. With onPress they become one press target together with media.
- footer is a separate row for buttons and links, outside the main press target.
- variant switches the surface: elevated (a soft shadow), outline (a hairline border) or filled (a muted fill).
- Your app owns navigation and data; the card only reports the tap.
Behavior and gestures
- Tapping the header, picture or body runs the card's main action, such as opening the detail screen.
- While a finger is down, the whole card shrinks very slightly and springs back on release, so it feels like one solid object.
- A successful tap plays a light haptic tap. Turn it off with haptics={false} when a parent already gives feedback.
- Buttons in the footer work on their own: tapping Save never also opens the card.
- A disabled card fades to half opacity and ignores taps, while footer buttons keep whatever state you give them.
- Without onPress the card is static: no press feedback, and only the footer is interactive.
Accessibility
- A tappable card is announced as a single button using the accessibilityLabel you pass, such as "Mountain walks, a quiet route above the valley". The types require that label whenever onPress is set.
- Inside a tappable card, the header, picture and body are hidden from VoiceOver and TalkBack so nothing is read twice; your label carries the summary.
- Footer buttons come after the card as their own focus stops, each with its own label.
- Add accessibilityHint to say what a tap does, for example "Opens the route".
- The tappable surface is at least 44 by 44 points and reports its disabled state to assistive tech.
- Header and body content you pass keep their own text styles; SwipeUI Text grows with Dynamic Type and follows your preset's contrast.
Motion
- Uses the
pressmotion role, so it follows your app's feel. Passmotionto tune this one instance. - Press feedback is a small scale-down on the shared press spring: about 2% in the smooth feel, up to 6% in bouncy.
- Releasing, or sliding your finger off, springs the card back to full size even mid-animation.
- Reduce Motion, or the none feel, removes the scale entirely; the tap and haptic still work.
- Static cards, with no onPress, never animate.
Performance
- A static card renders plain views with no animation, timers or subscriptions.
- The press scale runs on the UI thread through Reanimated, so pressing never re-renders your content.
Notes for AI
- Whenever you pass onPress, also pass accessibilityLabel with a short summary of the card.
- Keep everything interactive in footer. Nothing in header, media or children should be pressable when the card has onPress.
- Pick the variant for emphasis (elevated, outline or filled) instead of overriding background and shadow classes.
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.