β¨ react-native-animated-rolling-numbers
is a React Native component that animates numbers and compact notations (K, M, B, T) with customizable styles and animations. It's designed to create smooth, eye-catching transitions between numeric values.
readme.mp4
The example shown in the video is available here.
- β¨ Supports animated transitions for numeric values and symbols (e.g., commas, dots).
- π¨ Customizable digit styles and animation configurations.
- π Handles compact number formatting (e.g., 1K, 1M, etc.).
- π§ Easily customizable via props.
- π Supports reduce-motion and easing functions for animations.
- π’ Designed for both regular numbers and formatted numbers with signs (positive/negative) and commas.
npm install react-native-animated-rolling-numbers
# or
yarn add react-native-animated-rolling-numbers
Make sure you have react-native-reanimated
installed in your project. Follow the official installation guide here: react-native-reanimated installation.
Basic Example
import React, { useState } from "react";
import { View, StyleSheet, Button } from "react-native";
import { AnimatedRollingNumber } from "react-native-animated-rolling-numbers";
import { Easing } from "react-native-reanimated";
const App = () => {
const [value, setValue] = useState(1200);
return (
<View style={styles.container}>
<AnimatedRollingNumber
value={value}
showPlusSign
showMinusSign
useGrouping
enableCompactNotation
compactToFixed={2}
textStyle={styles.digits}
spinningAnimationConfig={{ duration: 500, easing: Easing.bounce }}
/>
<Button
onPress={() => setValue(value + Math.floor(Math.random() * 1000))}
title="Increase"
/>
<Button
onPress={() => setValue(value - Math.floor(Math.random() * 1000))}
title="Decrease"
/>
</View>
);
};
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: "center",
alignItems: "center",
},
digits: {
fontSize: 32,
fontWeight: "bold",
paddingHorizontal: 2,
color: "#4A90E2",
},
});
export default App;
The example shown in the video is available here.
The numeric value to be displayed and animated.
Whether to show the sign of the number (e.g., "+" or "-"). Defaults to false
.
Whether to show the minus sign for negative numbers. Defaults to true
.
Whether to show the plus sign for positive numbers. Defaults to false
.
Number of decimal places to show in normal notation. defaults to undefined
.
Whether to include commas/points in the number formatting (e.g.,1000987 -> 1,000,987). Defaults to false
.
Custom formatted text to display instead of the numeric value.
The locale to use for number formatting. Defaults to "en-US"
.
Enable compact notation for large numbers (e.g., 1K, 1M, 1B, 1T). Defaults to false
.
Number of decimal places to show in compact notation. Defaults to undefined
.
If true, only applies decimal precision for compact notation (K/M/B/T). Defaults to true
.
Example:
- If
fixedOnlyForCompact
istrue
andcompactToFixed
is2
, the number1500
will be displayed as1.50K
, but the number999
will be displayed as999
(no decimal places). - If
fixedOnlyForCompact
isfalse
andcompactToFixed
is2
, the number1500
will be displayed as1.50K
, and the number999
will be displayed as999.00
.
Style for the container wrapping the animated digits.
Style for the container wrapping each animated digit.
Props for the main text component.
Props for the numeric text components.
Props for the comma text component.
Props for the decimal point text component.
Props for the compact notation text components (K, M, B, T).
Props for the sign text component (if used).
Style for the main text component.
Style for the numeric text components.
Style for the comma text component.
Style for the decimal point text component.
Style for the compact notation text components.
Style for the sign text component.
Configuration for the digit animation. Supports:
duration: number
: Duration of the animation in milliseconds.reduceMotion: boolean
: Whether to reduce motion for accessibility.easing: EasingFunction
: Custom easing function for the animation.
Callback function that is invoked when the animation completes.
Custom function to animate the value change. Defaults to a bounce animation.
If you find this project useful and would like to support its ongoing development, consider buying me a coffee! Your support helps keep the creativity brewing and allows me to continue improving and maintaining this project. Thank you! βπ