Reac-Native-Number-Easing实现
来源:互联网 发布:如何确保js加载完全 编辑:程序博客网 时间:2024/06/03 17:40
在rn项目中做到了跟金额相关的项目,然后就想到做个类似余额宝金额跳动的效果,本来想找个第三方库省个事,然而在网上并没有,只有一个react的Number-Easing研究了一下作者的思想以后,尝试着改了一个rn的版本出来,反正能用。。。。,附上原作者ract版的github地址:https://github.com/javierbyte/react-number-easing
附上代码:
'use strict';import React, {Component,PropTypes} from 'react';import { Text} from 'react-native';import eases from 'eases';import TimerMixin from 'react-timer-mixin';export default class NumberEasing extends Component { static propTypes = { ease: PropTypes.string, speed: PropTypes.string, value: PropTypes.string.isRequired }; static defaultProps = { ease: 'quintInOut', speed: '2000', }; constructor(props) { super(props); this.timeout = null; this.startAnimationTime = (new Date()).getTime(); this.state = { displayValue: 0 } this.updateNumber = this.updateNumber.bind(this); } componentDidMount() { if (this.props.value == '0' || this.props.value == '00') { return; } this.updateNumber(); } updateNumber() { var now = new Date().getTime(); var elapsedTime = now - this.startAnimationTime; var progress = eases[this.props.ease](elapsedTime / this.props.speed); if (this.state.displayValue >= this.props.value) { this.setState({ displayValue: this.props.value }); TimerMixin.clearTimeout(this.timeout); return; } var currentDisplayValue = Math.round((this.props.value - this.state.displayValue) * progress + this.state.displayValue); this.setState({ displayValue: currentDisplayValue }); this.timeout = TimerMixin.setTimeout(this.updateNumber, 16); } componentWillUnmount() { TimerMixin.clearTimeout(this.timeout); } render() { return <Text style={this.props.style}> {this.state.displayValue} </Text> }};module.exports = NumberEasing;
package的dependencies要加入一下引用:"eases": "^1.0.6","react-timer-mixin": "^0.13.3",
使用的话以这样的方式:
<NumberEasing value={9876} speed={800} ease='quintInOut'/>
Git地址:https://github.com/xy898956/react-native-number-easing.git
0 0
- Reac-Native-Number-Easing实现
- Reac native (1) 环境搭建
- Reac-Native ScrollView回到顶部
- Reac Native-UI组件的封装
- Reac Native(一)windows环境搭建
- reac native 项目学习——GD
- 走进Reac
- 走进Reac
- 走进Reac
- angular\reac\vue总结
- Easing list
- jQuery Easing
- easing.js
- Reac学习笔记_reactSPA学习
- jQuery Easing 运动效果插件 easing.js
- jQuery easing 图解
- cocos2d - x easing 减速
- jQuery Easing 动画
- velocity中的表达式
- 十个非常好用的文件上传工具(插件)
- mysql优化 备份
- centos7安装pptpd (No package pptpd available)
- 深入理解 GCD
- Reac-Native-Number-Easing实现
- LeetCode:Reverse Linked List
- servlet涉及对象(补充)
- 单例模式解析
- Ad-Hoc(点对点)模式
- JS中 原型模式与构造模式
- ++i 与i++哪个效率更高?
- 封装、继承、多态、接口、枚举、委托、多线程、集合、事件、都明白了?
- MsgWaitForMultipleObjects