Animated.Event 在 React Native 中是如何工作的? [英] How does Animated.Event work in React Native?
本文介绍了Animated.Event 在 React Native 中是如何工作的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我理解正确吗?这两套代码是同一个意思吗?在性能或可靠性上有什么不同吗?
I'm I understanding it correctly ? Does this two set of code meant the same thing ?Does it have any difference in performance or reliability ?
<ScrollView
onScroll={Animated.event(
[{nativeEvent: {contentOffset: {y: this.state.scrollY}}}]
)}
>
</ScrollView>
和
handleScroll(e){
this.setState({ scrollY : e.nativeEvent.contentOffset.y });
}
<ScrollView
onScroll={(e) => this.handleScroll(e)}
>
</ScrollView>
谢谢
推荐答案
如果你想处理滚动,你可以这样使用:
If you want to handle the scroll you can use it this way:
handleScroll = (event) => {
//custom actions
}
<ScrollView
onScroll={Animated.event(
[{ nativeEvent: {
contentOffset: {
x: this.state.scrollY
}
}
}],{
listener: event => {
this.handleScroll(event);
}})
}>
</ScrollView>
这篇关于Animated.Event 在 React Native 中是如何工作的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文