Capture Famo.us Scrollview "scroll" event?

181 Views Asked by At

I'm trying to add a listener to scrolling on a Famo.us Scrollview on mobile.

From what I can find, the scrollview's sync emits start, update and end events. But in practice I'm finding that the end event is fired on touchend, not when the scrollview actually finishes scrolling given momentum. And update is fired on touchmove, again completely ignoring momentum.

How do I listen to actual scrolling?

2

There are 2 best solutions below

2
On BEST ANSWER

At version 0.3.1 of Famo.us there are four events you can use to keep track of some scrolling. Unfortunately, they are limited in what information you can get from them.

Events:

  • pageChange
  • onEdge
  • offEdge
  • settle

They will fire based on the options of your scroll view, so you will need to test. Here is some code to test quickly.

scrollview.on('pageChange', function(event){
  console.log('pageChange',event.direction, event.index);
});
scrollview.on('onEdge', function(){
  console.log('onEdge');
});
scrollview.on('offEdge', function(){
  console.log('offEdge');
});
scrollview.on('settle', function(){
  console.log('settle');
});
0
On

scrollview._scroller.on('update') CAN be listened to, but does not guarantee that the values provided are the actual scrolling displacement as the scrollview may decide to scale them.

However, this would allow you to tell whether or not the user is scrolling; combining this with scrollview.getVelocity you'd have all you'd need.