从数据源中添加/删除列表视图项时对其进行动画处理 [英] Animate listview items when they are added/removed from datasource

查看:31
本文介绍了从数据源中添加/删除列表视图项时对其进行动画处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以告诉我如何做到这一点,例如添加时将高度从 0 动画化,删除时返回 0?

Can someone give me an idea of how this can be done, e.g. animate the height from 0 when added and back to 0 when removed?

推荐答案

添加动画很容易,只需在 componentDidMount 中使用 Animated 和 listRow ,例如:

Animation when added is easy, just use Animated in componentDidMount with your listRow , for example:

componentDidMount = ()=> {
    Animated.timing(this.state._rowOpacity, {
        toValue: 1,
        duration: 250,
    }).start()
}

在 react-native 中,在卸载之前对组件进行动画处理要困难得多.您应该为 ListView 设置一个处理程序.当数据源改变时,比较数据,启动动画隐藏删除的行,并为 ListView 设置新的数据源.

Animate a component before unmount is much harder in react-native. You should set a handler for ListView. When dataSource changed, diff the data, start Animated to hide removed row, and set new dataSource for ListView.

这篇关于从数据源中添加/删除列表视图项时对其进行动画处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆