0

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?

nicholas
  • 14,184
  • 22
  • 82
  • 138

2 Answers2

2

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');
});
talves
  • 13,993
  • 5
  • 40
  • 63
  • Thanks! Great answer. That will work for this project. One follow-up question: how is pageChange configured? I see the events firing, but don't see how it's defining a page. Is there any documentation on this? – nicholas Dec 01 '14 at 02:14
  • @nicholas I have not seen any documentation yet on these events. Your best bet is to look at the **[code](https://github.com/Famous/famous/blob/develop/src/views/Scrollview.js#L382-L393)**. Emitted when it normalizes state. When there is a change of the node index. – talves Dec 01 '14 at 16:13
0

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.

Stephan Bijzitter
  • 4,425
  • 5
  • 24
  • 44