react-native-counter-animation
TypeScript icon, indicating that this package has built-in type declarations

1.0.5 • Public • Published

React Native Counter Animation

A number animation library for adding some flair to your data

Screenshot

Installation

npm i -S react-native-counter-animation
# or
yarn add react-native-counter-animation 

Usage

import { View, Easing } from "react-native";
import { useEffect, useRef, useState } from "react";
import { AnimatedNumber } from "react-native-counter-animation";

const MyComponent = () => {
  const [value, setValue] = useState(5000);
  const timer = useRef<number | null>(null);

  useEffect(() => {
    timer.current = setInterval(() => {
      setValue(Math.floor(Math.random() * 5000));
    }, 5000);
    return () => {
      clearInterval(timer.current);
      timer.current = null;
    }
  });

  return (
    <View>
      {/* ...your component code */}
      <AnimatedNumber
        delay={200}
        stagger={0}
        value={value}
        duration={700}
        easing={Easing.out(Easing.ease)}
        style={{ color: "#fff", fontWeight: "800" }} />
    </View>
  );
}

Options

delay: A millisecond duration to defer the animation

stagger: A millisecond duration to stagger each character's animation

duration: A millisecond duration for the animation

value: A string or number to animate to

easing: An easing function such as a Cubic Bezier

style: Any styling you wish to apply to your text

Package Sidebar

Install

npm i react-native-counter-animation

Weekly Downloads

70

Version

1.0.5

License

MIT

Unpacked Size

30.6 kB

Total Files

28

Last publish

Collaborators

  • alexfigliolia