我正在使用https://facebook.github.io/react-native/docs/scrollview.html,它有一个方便的onScroll
道具,但是当用户停止滚动时该如何获取?如何检查用户何时停止滚动?
基本上,我想在用户滚动时隐藏一个按钮,当他们不在时显示。
我正在使用https://facebook.github.io/react-native/docs/scrollview.html,它有一个方便的onScroll
道具,但是当用户停止滚动时该如何获取?如何检查用户何时停止滚动?
基本上,我想在用户滚动时隐藏一个按钮,当他们不在时显示。
在您的组件状态中,存储上次收到滚动事件的时间。在您的渲染方法中,检查最后一次滚动事件发生的时间,并确定您的按钮是否应该再次可见。
粗糙例如:
// Observe the scroll events.
<ScrollView onScroll={(e) => {
this.setState({lastScroll: new Date()})
}} />
// Check if the last scroll happened later than 300ms ago.
if (this.state.lastScroll.getTime() < (new Date()).getTime() - 300) {
// Render the button.
}
阅读本文件(https://facebook.github.io/react-native/docs/gesture-responder-system.html)nativeEvent元素可以帮助你 –