1

I need to SHOW a view when scroll is started and HIDE a view when scroll is stopped.

To detect the scroll movement, there is two ways:

  1. Called when the user begins to drag the scroll view.

    onScrollBeginDrag={this.showView}
    onScrollEndDrag={this.hideView}
    
  2. Called when the momentum scroll starts and Ends

    onMomentumScrollBegin={this.showView}
    onMomentumScrollEnd={this.hideView}
    

Exptected Behaviour:

If continues scroll is happening, it should not hide the view even onScrollEndDrag is called and still show the view until onMomentumScrollEnd.

If continues scroll is not active, its should hide when onScrollEndDrag called

Actual Behaviour:

If continues scroll is happening, its hide the view when onScrollEndDrag is called and shows the view again until onMomentumScrollEnd. So in between view is disappeared and then its appears when drag released.

Balasubramanian
  • 5,274
  • 6
  • 33
  • 62

1 Answers1

1

Call a debounced function in onScroll.

Debouncing will mean it is called at the end (or start) of a bunch of events. More Info

// Debounce
this.ViewVisibility = lodash.debounce(this.ViewVisibility, 100);

onScroll={() => {
  this.ViewVisibility();
}}

ViewVisibility = () => {
  console.log('Debouncing');
  this.hideView();
}
Balasubramanian
  • 5,274
  • 6
  • 33
  • 62