Animated counter
UI-thread numeric interpolation with serializable locale formatting and final-value accessibility.
npx @swipeui/cli add animated-counterWhen to use it
- Dashboards where a number counts up when it appears or changes, such as revenue or followers.
- Celebratory totals after finishing a workout or a level.
- Numbers with decimals and grouping that should animate smoothly.
When not to use it
- Exact money or IDs that must never show in-between values. Use Slot text.
- Static numbers. Use Text.
- Countdowns to a time. Use Countdown.
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 animated-counter- Adds
components/swipeui/ui/counter-format.ts,components/swipeui/ui/animated-counter.tsxand 2 shared helpers. - Installs react-native-reanimated, uniwind, react-native-worklets, clsx, tailwind-merge. In Expo apps it uses
npx expo installso versions match your SDK.
Usage
import { AnimatedCounter } from '@/components/swipeui/ui/animated-counter';
<AnimatedCounter value={1240.5} format="currency" currency="USD" precision={2} label="Balance" />;Examples
integer counts steps, decimal logs a walk, and currency adds funds to a balance. The app and website share these named boards, with actions and Reset outside the card.
Settings
| Setting | Default | Behavior |
|---|---|---|
value | required | Finite target within the safe numeric range. |
precision | 0 | Decimal places from 0 to 6; applies to every format. |
format | 'decimal' | 'decimal', 'compact', 'percent' or 'currency'. Compact counts within the same locale unit; a unit change holds the previous display and snaps at the end. Percent takes a fraction (0.25 is 25%). |
currency | absent | ISO code such as USD or EUR; required for currency format. |
prefix | '' | Text before the formatted number, also spoken. |
suffix | '' | Text after the formatted number, also spoken. |
locale | device locale | Locale for digits, separators, signs and affix positions. |
useGrouping | true | Locale grouping. |
label | absent | Spoken purpose: label, colon, prefix, formatted target and suffix. |
motion | app feel | Shared number transition; Reduce Motion jumps to the target. |
className | absent | Root classes. |
textClassName | 'font-mono text-title-1' | Number style classes. Native ink defaults to the scheme's foreground token; an explicit colour class overrides it. |
style | absent | Native root layout escape hatch. |
testID | absent | Root ID; the read-only value appends -value. |
Formatting
Locale parts are resolved on the JS thread once per target. Serializable digits, separators, scale and affixes format the intermediate values on the UI thread, without calling Intl per frame. The existing formatter fallback for engines without formatToParts remains supported.
For exact balances that must never show intermediate amounts, use Slot text. This counter shows an approximate animated journey to the exact formatted target.
Accessibility
One accessible element reports the final target with the prefix and suffix. The read-only animated text is hidden from assistive technology. Native screen-reader, Dynamic Type and performance checks remain pending at 7.9.
Behavior and gestures
- Decimal, compact, percent and currency targets use locale parts resolved once on JS; frames format on UI.
- prefix and suffix appear in both the text and spoken target.
- Compact unit changes hold the previous display and snap at completion; counts within a unit remain continuous.
Accessibility
- Screen readers hear only the final number, never the in-between frames.
- Add label so the number has context, for example "Steps today: 8,240".
- Formatting follows the device locale unless you set one.
Motion
- Uses the
numbermotion role, so it follows your app's feel. Passmotionto tune this one instance. - Counting uses the number role on the UI thread.
- Reduce Motion jumps straight to the final value.
Performance
- Text updates happen on the UI thread without React re-renders.
Notes for AI
- Pass a number for value; set precision for decimals.
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.