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}/>
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容