npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@bankify/react-native-animate-number

v0.2.1

Published

Animated number component

Downloads

834

Readme

react-native-animate-number npm version circle CI

Customizable react native component for number animations.

Installation

$ yarn add @bankify/react-native-animate-number

Usage

import AnimateNumber from '@bankify/react-native-animate-number'

Examples

Basic

The only required property is value, when this property changes, it automatically interpolates value and performs animation.


<AnimateNumber value={100}/>

Formatting

You can customize text format by specifying formatter prop, this property must be a function.


<AnimateNumber value={100} formatter={(val) => {
    return '$ ' + parseFloat(val).toFixed(2)
  }}/>

Timing function

There're 3 built-in timing functions which are linear, easeIn, and easeOut. It is also possible customize your timing function, see examples bellow.

Built-in timing function


<AnimateNumber value={100} timing="linear"/>
<AnimateNumber value={100} timing="easeOut"/>
<AnimateNumber value={100} timing="easeIn"/>

Customized timing function

Customized timing function returns a number which represents the length of animation frame.

interval

Basic interval length of animation frame, default value is 14 ms. You can change this value by interval prop.

progress

A float number between 0 to 1, which means the progress of animation.


<AnimateNumber value={200}
  countBy={1}
  timing={(interval, progress) => {
    // slow start, slow end
    return interval * (1 - Math.sin(Math.PI*progress) )*10
  }}/>

the above example will make an animation like this

timing function example

Counting

By default this component calculates value increment of each animation frame, but you can customize this rule by set prop countBy.


<AnimateNumber value={100} countBy={1} />

But keep in mind if the countBy value is relative small than value, the animation may persists for a very long time. Like the following example, it will tasks 150 seconds to finish the animation.


<AnimateNumber value={10000} interval={15} countBy={1} />

Customize content rendering

By default this component renders a <Text> component. You can provide your own component by setting the prop renderContent.

<AnimateNumber value={100} countBy={1} renderContent={(displayValue) => #Your own component} />

Props

value:number(required)

The value of AnimateNumber component.

countBy:number(optional default to null)

Set this property to force the component's value increase/decrease by this number.

interval:number(optional default to 14)

Base interval of each animation frame, in ms.

steps:number(optional default to 45)

Set total frame number of animation, say, if interval is 14 and steps is 30, the animation will take 14x30ms to finish when it uses linear timing function.

timing: 'linear' | 'easeOut' | 'easeIn' | () => number

Custom timing function or use a default timing function.

formatter: () => string(optional)

This prop accepts a function which returns a string as displayed value.

renderContent: (displayValue: number) => React.Node (optional)

This prop accepts a function with the displaying value as the parameter and expects a React Node as returned value

onProgress: () => void(optional)

A function that triggers when text state has updated.

onFinish: () => void(optional)

A function that triggers when animation completes.