Giter VIP home page Giter VIP logo

react-native-animate-number's Introduction

react-native-animate-number npm version circle CI

Customizable react native component for number animations.

Installation

$ npm install react-native-animate-number

Usage

import AnimateNumber from '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} />

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.

onProgress: () => void(optional)

A function that triggers when text state has updated.

onFinish: () => void(optional)

A function that triggers when animation completes.

react-native-animate-number's People

Contributors

caleyd avatar cinder92 avatar coleturner avatar wkh237 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

react-native-animate-number's Issues

How to reset when changing screen and come back

Hello,
The animation works as expected after the first display, but I can't get how to reset it, to make it works for the next taps, for example when I change screen and come back to this one...

Animation is broken

Using <AnimateNumber value={1000} timing="easeIn" /> shows really weird visual results. The numbers in the animation are all over the place before it reaches the final count.

Warning: componentWillUpdate has been renamed, and is not recommended for use.

See https://fb.me/react-async-component-lifecycle-hooks for details.

* Move data fetching code or side effects to componentDidUpdate.
* Rename componentWillUpdate to UNSAFE_componentWillUpdate to suppress this warning in non-strict mode. In React 17.x, only the UNSAFE_ name will work. To rename all deprecated lifecycles to their new names, you can run `npx react-codemod rename-unsafe-lifecycles` in your project source folder.

Please update the following components: AnimateNumber

This warning comes up in dev tools for newer versions of React 16.X.

Reverse count

Didn't found way animate in decrement order
eg start from 60 end with 0

Bug: Wrong declaration of props function in index.js

So, when I used this package with my project, I encountered this bug

   17 | export default class AnimateNumber extends Component {
   18 |
  > 19 |   props : {
      |         ^
   20 |     countBy? : ?number,
   21 |     interval? : ?number,
   22 |     steps? : ?number,

es2015 preset error with this component

First of all......... thank you thank you for creating this component! I just grabbed it and I'm trying to just import it per the instructions in the README.md and I'm running into the following error. I'm on RN 0.25.1 if that matters.

image

Is this project abandoned?

Hi, @wkh237 there are some opened issues and unmerged pull requests here. There are no problem if this project has been abandoned just let us know. Thank you

So slow onAndroid

I am now waiting it to finish the animation 😂 on android device .. It is not yet done .

However, in iOS, it works quickly

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.