@bankify/react-native-animate-number

中文文档
0.2.1发布于 2018/12/08MITCommonJS近 30 天下载 2672

Animated number component

原始使用文档
文档目录9 节
  1. Installation
  2. Usage
  3. Examples
  4. Basic
  5. Formatting
  6. Timing function
  7. Counting
  8. Customize content rendering
  9. Props

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.

版本与发布记录

@bankify/react-native-animate-number 共发布 2 个版本,首次发布于 2018/12/08;过去 12 个月发布了 0 个版本。

版本发布日期距今
0.2.1latest2018/12/087 年前
0.2.02018/12/087 年前

关于 @bankify/react-native-animate-number 的常见问题

@bankify/react-native-animate-number 是什么?

Animated number component

如何安装 @bankify/react-native-animate-number?

在项目目录运行 npm install @bankify/react-native-animate-number,或使用 pnpm add / yarn add / bun add。

@bankify/react-native-animate-number 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/bankify__react-native-animate-number 是否存在。

@bankify/react-native-animate-number 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@bankify/react-native-animate-number 可以商用吗?

@bankify/react-native-animate-number 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@bankify/react-native-animate-number 的下载量有多少?

根据 npm 官方下载统计,@bankify/react-native-animate-number 在 2026/10/08 – 2026/11/06 这 30 天内被下载 2,672 次,日均约 89 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@bankify/react-native-animate-number 还在维护吗?

最新版本 0.2.1 发布于 2018/12/08(7 年前);至今共发布 2 个版本,其中过去 12 个月发布了 0 个;首次发布于 2018/12/08。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。