Roll Number
React Native (Expo)
A React Native odometer whose digits roll to their new value, last digit first, with separators, decimals and negative numbers.
An odometer. Each digit is a column that rolls to its new value, starting from the last digit and moving left. Thousands separators stay put, the number may grow or shrink in length, and screen readers get the whole value as one piece of text instead of a column of digits. Built for React Native and Expo with react-native only; this page previews it in the browser through react-native-web.
Installation
CLI
npx @modus-ui/cli add roll-numberManual
- Copy the code from the component tab.
- Create a file at
components/ui/roll-number.tsx. - Paste the code.
It needs no packages beyond react-native, which your Expo or React Native app already has.
Usage
tsx
Props
| Prop | Type | Default | Description |
|---|---|---|---|
value | number | - | The number to show. Negative values get a minus sign. |
decimals | number | 0 | Digits after the decimal point. |
prefix | string | - | Text before the number, such as a currency symbol. |
suffix | string | - | Text after the number, such as a unit. |
fontSize | number | 40 | Size of the digits. Their column width follows it. |
colors | Partial<RollNumberColors> | - | Overrides text, the color of the digits and the surrounding text. |
duration | number | 700 | How long each digit takes to roll, in milliseconds. |
style | StyleProp<ViewStyle> | - | Style for the container. |
Comments