首页 > 其他 > 详细

React-Native Animated.createAnimatedComponent

时间:2020-02-29 21:56:01      阅读:329      评论:0      收藏:0      [点我收藏+]

React-Native Animated.createAnimatedComponent

export function createAnimatedComponent(component: any): any;

可以将自定义的组件转变成支持动画的组件

大概就是:CustomComponent =>Animated.View

举例实现:自定义一个组件,动画改变其宽高

 
技术分享图片
QQ20181106-150802.gif
class Sub extends PureComponent {

    render() {
        const {width, height} = this.props
        return (
            <View style={{width,height,backgroundColor: blue}}>

            </View>
        );
    }
}

const ABC = Animated.createAnimatedComponent(Sub)


constructor(props) {
        super(props);
        this.state = {
            width: new Animated.Value(0),
            height: new Animated.Value(0)
        }
    }


    componentDidMount(){
        Animated.parallel([
            Animated.timing(this.state.width,{
                toValue: 200,
                duration: 5000
            }),
            Animated.timing(this.state.height,{
                toValue: 200,
                duration: 5000
            })
        ]).start()
    }

<ABC width={this.state.width} height={this.state.height}/>

 

React-Native Animated.createAnimatedComponent

原文:https://www.cnblogs.com/plBlog/p/12386081.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!