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-toggleWhen 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.tsand 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 installso versions match your SDK.
Usage
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
| Prop | Type | Default | Description |
|---|---|---|---|
plans? | | — | The plans, side by side. |
value? | | — | The chosen plan (controlled). |
defaultValue? | | | The plan chosen at first (uncontrolled). |
onValueChange? | | — | Reports the chosen plan's value. |
currency? | | | Currency for |
locale? | | | Locale for prices. |
formatPrice? | | | Your own price format, given minor units. |
showCta? | | | The full-width button under the cards; its label follows the chosen plan. |
onContinue? | | — | The button's action, given the chosen plan. A promise shows a spinner until it settles. |
onRestore? | | — | "Restore purchases" under the button, shown when given. |
onTerms? | | — | "Terms" under the button, shown when given. |
onPrivacy? | | — | "Privacy" under the button, shown when given. |
swipeToSwitch? | | | ★ Swipe across the cards to switch plans, with a tick. |
size? | | | Card and button size. |
cardMinHeight? | | | Minimum plan height in points; content can grow for larger text. |
monthlyPrice? | | — | 1.x: the monthly price, already formatted. |
yearlyPrice? | | — | 1.x: the yearly price, already formatted. |
savingsLabel? | | — | 1.x: a savings line on the yearly card. |
disabled? | | | No switching or continuing. |
haptics? | | | Haptics: a switch, or per part ( |
motion? | | | Ring, check, card and button motion. |
messages? | | | Built-in strings. |
className? | | — | Root classes. |
style? | | — | Root style. |
testID? | | — | Root identifier; cards append |
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.
onContinuegets 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 lacksformatToParts), so the app and the web match; passformatPricefor your own format. - Restore purchases, Terms and Privacy appear for the handlers you pass.
Billing toggle settings
| Prop | Does | Default |
|---|---|---|
| plans | The cards, side by side | two from the 1.x props |
| value / defaultValue | The chosen plan | the second plan |
| currency / locale / formatPrice | How minor-unit prices are written | USD, device, Intl |
| cardMinHeight | Minimum card height in points; content can grow | 144 with notes, 88 for simple prices |
| showCta / onContinue | The full-width button and its action | true, none |
| onRestore / onTerms / onPrivacy | The links under the button | hidden |
| swipeToSwitch | ★ Swipe across the cards to switch | true |
| size | md or lg cards and button | md |
| disabled | No switching or continuing | false |
| haptics | All, or { select, detent, limit } | on |
| messages | Button, savings, link and period strings | English |
| motion | A local motion feel or override | the 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,morphandpressmotion roles, so it follows your app's feel. Passmotionto 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 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.