SwipeUI

Billing toggle

A paywall footer: plan cards side by side with a gliding ring and corner check, savings that turn into the amount, a button that follows the plan, and Restore · Terms · Privacy.

npx @swipeui/cli add billing-toggle
Variant
Preset
Material
Scheme
Feel
Real free component with a browser animation bridge. Native motion, haptics and materials need a device.

When to use it

  • The bottom of a paywall: two or three subscription periods, the button that buys and the Restore, Terms and Privacy links.
  • Pricing screens where the yearly plan's savings and per-month price should be clear at a glance.
  • Plan changes where the price comes from your store, already formatted.

When not to use it

  • Plans that differ in features, not period. Use Radio cards.
  • Switching a view between periods without buying. Use Segmented control.

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 billing-toggle
  • Adds components/swipeui/ui/billing-toggle.tsx, components/swipeui/ui/use-billing-toggle.ts and 14 shared helpers.
  • Installs react-native-gesture-handler, react-native-reanimated, react-native-worklets, uniwind, clsx, tailwind-merge, expo-haptics, class-variance-authority, react-native-svg. In Expo apps it uses npx expo install so versions match your SDK.

Usage

app/paywall.tsx
import { BillingToggle } from '@/components/swipeui/ui/billing-toggle';

<BillingToggle
  plans={[
    { value: 'monthly', period: 'Monthly', price: 999, per: 'per month', months: 1 },
    { value: 'yearly', period: 'Yearly', price: 7999, per: 'per year', months: 12, badge: 'Best value' },
  ]}
  onContinue={(plan) => purchases.buy(plan.value)}
  onRestore={purchases.restore}
  onTerms={openTerms}
  onPrivacy={openPrivacy}
/>;

Prices are integer minor units (7999 is $79.99) in currency. With months, each longer plan shows its savings against the shortest plan. Savings sit centered between the price and the bottom note; all plan cards keep the same height.

Examples

Three plans in euros, with a struck old price:

<BillingToggle
  currency="EUR"
  plans={[
    { value: 'weekly', period: 'Weekly', price: 399, months: 0.25 },
    { value: 'monthly', period: 'Monthly', price: 1299, months: 1 },
    { value: 'yearly', period: 'Yearly', price: 8999, compareAt: 15588, months: 12 },
  ]}
/>

Prices already formatted by your store (the 1.x props still work):

<BillingToggle monthlyPrice="$9 / month" yearlyPrice="$90 / year" savingsLabel="Save $18 a year" />

API reference

BillingToggleProps

PropTypeDefaultDescription
plans?readonly BillingPlan[]—

The plans, side by side.

value?string—

The chosen plan (controlled).

defaultValue?stringthe second plan, else the first

The plan chosen at first (uncontrolled).

onValueChange?((value: string) => void)—

Reports the chosen plan's value.

currency?string'USD'

Currency for price and compareAt (ISO 4217).

locale?stringthe device's

Locale for prices.

formatPrice?FormatPrice`Intl.NumberFormat(...).format()` (Hermes-safe)

Your own price format, given minor units.

showCta?booleantrue

The full-width button under the cards; its label follows the chosen plan.

onContinue?((plan: BillingPlan) => unknown)—

The button's action, given the chosen plan. A promise shows a spinner until it settles.

onRestore?(() => void)—

"Restore purchases" under the button, shown when given.

onTerms?(() => void)—

"Terms" under the button, shown when given.

onPrivacy?(() => void)—

"Privacy" under the button, shown when given.

swipeToSwitch?booleantrue

★ Swipe across the cards to switch plans, with a tick.

size?"lg" | "md"'md'

Card and button size.

cardMinHeight?number144 with notes, 88 for simple prices

Minimum plan height in points; content can grow for larger text.

monthlyPrice?string—

1.x: the monthly price, already formatted.

yearlyPrice?string—

1.x: the yearly price, already formatted.

savingsLabel?string—

1.x: a savings line on the yearly card.

disabled?booleanfalse

No switching or continuing.

haptics?boolean | SelectionHapticstrue

Haptics: a switch, or per part (select for a plan, detent for a swipe, limit at the ends).

motion?MotionOverridethe app's feel

Ring, check, card and button motion.

messages?Partial<BillingToggleMessages>English

Built-in strings.

className?string—

Root classes.

style?StyleProp<ViewStyle>—

Root style.

testID?string—

Root identifier; cards append -<value>, plus -plans, -cta, -restore, -terms, -privacy, -ring.

A plan has value, period, price (or priceText), per, months, compareAt, line, badge, savings (false hides them), cta and disabled.

Composition and behavior

  • Tap a card to choose it: one ring glides to it and its savings turn from "Save 33%" into the amount saved. The button's label follows the plan.
  • ★ Swipe across the cards to step to the next or previous plan, with a tick; the ends answer with a warning tick. On the web, the arrow keys do the same.
  • onContinue gets the chosen plan; return a promise to show a spinner until it settles. Wire it to your purchase adapter; the component never imports a store SDK.
  • Prices are formatted with Intl.NumberFormat(...).format() only (Hermes lacks formatToParts), so the app and the web match; pass formatPrice for your own format.
  • Restore purchases, Terms and Privacy appear for the handlers you pass.

Billing toggle settings

PropDoesDefault
plansThe cards, side by sidetwo from the 1.x props
value / defaultValueThe chosen planthe second plan
currency / locale / formatPriceHow minor-unit prices are writtenUSD, device, Intl
cardMinHeightMinimum card height in points; content can grow144 with notes, 88 for simple prices
showCta / onContinueThe full-width button and its actiontrue, none
onRestore / onTerms / onPrivacyThe links under the buttonhidden
swipeToSwitch★ Swipe across the cards to switchtrue
sizemd or lg cards and buttonmd
disabledNo switching or continuingfalse
hapticsAll, or { select, detent, limit }on
messagesButton, savings, link and period stringsEnglish
motionA local motion feel or overridethe app's feel

Behavior and gestures

  • Tap a card to choose it: one ring glides to it on the select spring, a check grows in its corner and its savings turn from "Save 17%" into "You save $19.89".
  • ★ Swipe across the cards to step to the next or previous plan, with a tick; the ends answer with a warning tick (`swipeToSwitch`).
  • The full-width button's label follows the plan (rolling only the changed letters); a promise from `onContinue` shows a spinner until it settles.
  • Restore purchases, Terms and Privacy appear under the button for the handlers you pass.
  • On the web, left and right arrows switch plans (mirrored in right-to-left layouts).

Accessibility

  • The cards are a radio group named "Plans"; each card is a radio whose name reads the period, price, old price, per-month note, savings, line and badge.
  • A swiped change is announced ("Yearly chosen"). Swiping always has a tap path.
  • Only show savings and old prices that are true for the user's region; they come from your prices, never from formatted strings.

Motion

  • Uses the select, toggle, morph and press motion roles, so it follows your app's feel. Pass motion to tune this one instance.
  • The ring glides on the select spring and snaps on a resize; the corner check grows and draws on the toggle role; savings rise in on the morph role; the button's label rolls its changed letters.
  • Reduce Motion: the ring jumps, the check appears without drawing, savings fade; haptics stay.

Performance

  • Prices are formatted once per render with `Intl.NumberFormat(...).format()`; the ring and check animate on the UI thread.

Notes for AI

  • Prices are integer minor units (`price: 7999` is $79.99) in `currency`; pass `priceText` for a store-formatted string instead. `formatPrice` overrides formatting.
  • Give `months` (1, 12) to get the per-month note and savings against the shortest plan; `savings: false` hides them.
  • Wire `onContinue` to your purchase adapter (it can return a promise); never import a store SDK into the component.
  • 1.x `monthlyPrice`, `yearlyPrice` and `savingsLabel` still render two cards.

Compatibility

Runs onSupported
Expo SDK 57Yes
Expo SDK 58Yes
React Native CLI (with Expo modules)Yes
Expo GoYes
iOSYes
AndroidYes

This table describes API support and static bundle checks. Native runtime, device accessibility and bare Uniwind compatibility remain pending.

Related items