我正在使用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元素可以幫助你 –