RN animated帧动画

本文介绍了一个使用React和Animated组件创建动态效果的方法。通过定义动画序列,实现了一系列元素的连续动画展示,每个元素的动画效果包括从透明到可见的过渡,动画持续时间为50毫秒。代码中展示了如何初始化动画值,设置动画序列,并在组件加载完成后自动开始动画。

效果图:

代码:

export default class AnimationFrameScene extends Component {

    constructor () {
        super()
        this.animatedValue = []
        arr.forEach((value) => {
            this.animatedValue[value] = new Animated.Value(0)
        })
    }

    componentDidMount () {
        this.animate()
    }

    animate () {
        const animations = arr.map((item) => {
            return Animated.timing(
                this.animatedValue[item],
                {
                    toValue: 1,
                    duration: 50
                }
            )
        })
        Animated.sequence(animations).start()
    }

    render() {
        const arr = []
        for (var i = 0; i < 500; i++) {
            arr.push(i)
        }

        const animations = arr.map((a, i) => {
            return <Animated.View key={i} style={{opacity: this.animatedValue[a], height: 20, width: 20, backgroundColor: 'red', marginLeft: 3, marginTop: 3}} />
        })

        return (
            <View style={styles.container}>
                {animations}
            </View>
        );
    }
}

const styles = StyleSheet.create({
    container: {
        flex: 1,
        flexDirection: 'row',
        flexWrap: 'wrap'
    },


});

 

转载于:https://www.cnblogs.com/hualuoshuijia/p/10184759.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值