Tidus Smith Tidus Smith - 2 years ago 91
React JSX Question

How do I check when the user has stopped scrolling?

I am using https://facebook.github.io/react-native/docs/scrollview.html, which has a handy

prop, but how do I get when the user has stopped scrolling?

Basically, I'd like to hide a button when the user is scrolling, show it when they aren't.

Answer Source

In your component state, store the last time at which you've received a scroll event. In your render method, check when the last scroll event happened and decide whether your button should become visible again or not.

Rough example:

// 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.
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download