美文网首页
React-Native Animated.createAnim

React-Native Animated.createAnim

作者: 精神病患者link常 | 来源:发表于2018-11-06 15:09 被阅读38次

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.createAnim

      本文链接:https://www.haomeiwen.com/subject/azduxqtx.html