IjzerenHein / famous-flex

Animatable layouts, FlexScrollView & widgets for famo.us.
MIT License
279 stars 44 forks source link

emit touchstart and touchend #97

Closed nicholasareed closed 9 years ago

nicholasareed commented 9 years ago

Better user experience for users to do linked scrolling between a single vertical FlexScrollView holding multiple horizontal FlexScrollViews. Previously using only scrollend instead of touchend results in any scrolling being blocked until scrollend (where, instead a user would expect to be able to scroll something else as soon as their finger is lifted).

Horizontal scrollers (create multiple of these): var elem = ...a FlexScrollView; HorizontalScrolls.push(elem); elem.on('scrollstart', function(event) { VerticalFlex.setOptions({ enabled: false }); elem.setOptions({ touchMoveDirectionThresshold: undefined }); }); elem.on(['scrollstop','touchend','touchcancel'], function(event) { VerticalFlex.setOptions({ enabled: true }); elem.setOptions({ touchMoveDirectionThresshold: 0.2 }); });

Vertical scroller: // When the vertical scrollview starts scrolling, capture all events // and disable scrolling on the horizontal scrollview VerticalFlex.on('scrollstart', function(event) { HorizontalScrolls.forEach(function(hView){ hView.setOptions({ enabled: false }); }); VerticalFlex.setOptions({ touchMoveDirectionThresshold: undefined }); }); VerticalFlex.on(['scrollstop','touchend','touchcancel'], function(event) { HorizontalScrolls.forEach(function(hView){ hView.setOptions({ enabled: true }); }); VerticalFlex.setOptions({ touchMoveDirectionThresshold: 0.5 }); });

IjzerenHein commented 9 years ago

Aweome dude! I'll have a closer look at this later this week.

IjzerenHein commented 9 years ago

Hey Nick, I've modified your suggestion a bit. Instead of emitting the 'touchstart' and 'touchend' events, I've implemented a more generic mechanism of so called 'swipe' events ('swipestart', 'swipeupdate' and 'swipeend'). These events are emitted when you use touch but also when you use the mouse (when the option 'mouseMove' is enabled). Also, they are only emmited once when you start touching and stop touching (as opposed to the default 'touchstart' and 'touchend' events, which are emitted for every finger that touches and releases the screen).

Let me know whether these events help you to improve the user experience for vertical/horizontal scrolling.