[React Native] Animate Styles of a React Native View with Animated.timing
2024-09-06 12:21:11
In this lesson we will use Animated.timing to animate the opacity and height of a View in our React Native application. This function has attributes that you can set such as easing and duration.
import React, {Component} from 'react';
import {Text, View, StyleSheet, Image, Animated, Easing} from 'react-native'; var styles = StyleSheet.create({
container: {
backgroundColor: '#48BBEC',
paddingBottom:
},
name: {
alignSelf: 'center',
fontSize: ,
marginTop: ,
marginBottom: ,
color: 'white'
},
handle: {
alignSelf: 'center',
fontSize: ,
color: 'white'
},
image: {
height: ,
width: ,
borderRadius: ,
marginTop: ,
alignSelf: 'center'
}
}); class Badge extends React.Component {
constructor(props){
super(props);
this.state = {
fadeAnim: new Animated.Value(),
bounceAnim: new Animated.Value()
}
}
componentDidMount() {
Animated.timing(
this.state.fadeAnim,
{toValue: , duration: }
).start();
Animated.timing(
this.state.bounceAnim,
{toValue: , duration: , easing: Easing.bounce}
).start();
}
render(){
const animatedTextStyle = {
opacity: this.state.fadeAnim,
};
const animateImageStyle = {
opacity: this.state.bounceAnim
};
return (
<View style={styles.container}>
<Animated.Image style={[styles.image, animateImageStyle]} source={{uri: this.props.userInfo.avatar_url}}></Animated.Image>
<Animated.Text style={[styles.name,animatedTextStyle]}> {this.props.userInfo.name} </Animated.Text>
<Animated.Text style={[styles.handle, animatedTextStyle]}> {this.props.userInfo.login} </Animated.Text>
</View>
)
}
} /**
* Make sure when when user the Badge component, the userInfo object is there
* @type {{userInfo: *}}
*/
Badge.propTypes = {
userInfo: React.PropTypes.object.isRequired
}; module.exports=Badge;
最新文章
- Elasticsearch聚合 之 Range区间聚合
- Cxgrid获取选中行列,排序规则,当前正在编辑的单元格内的值
- linux 用户之间的切换
- IOS 蓝牙相关-app作为外设被连接的实现(3)
- Unity3D 调用模态对话框/Unity3D MessageBox
- Dynamic CRM 2013学习笔记(三十八)流程1 - 操作(action)开发与配置详解
- 不要过早退出循环 while(1){no break}
- UIView与CALayer的区别
- sqlserver 常用sql语句
- ssh 密钥详解
- http://msh.baidu.com/UTWpR6wY4722
- android fragment传递参数_fragment之间传值的两种方法
- java——String的那边破事
- bzoj2683简单题 cdq分治
- 【转载】阿里云服务器为网站选配Https证书
- pandas数据清洗策略1
- 【Git】 GitLab简单使用
- C++虚表详解
- 从urllib2的内存泄露看python的GC python引用计数 对象的引用数 循环引用
- 【PyQt5-Qt Designer】对话框系列