IjzerenHein / famous-flex

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

FlexScrollview sync displacement #86

Closed Wenape closed 9 years ago

Wenape commented 9 years ago

I'm using the Meteor version of famous-flex, but I'm posting here because of the nature of my problem.

I implemented the following functionality when working with the regular Scrollview. A HeaderFooterLayout contains a Scrollview as it's content. If the Scrollview is on it's initial position and you start dragging down (content on edge), the whole HeaderFooterLayout starts closing like a drawer. I also setPosition(0) on the Scrollview update event to counteract the "overscroll" effect. This is done with the following code:

sync.on('update', function (data) {
  var currentPosition = FView.byId('HeaderFooterLayout').modifier._output.transform[13];
  var displacement = FView.byId('Scroller').view._displacement;

  if (displacement < 0) {
    FView.byId('Scroller').view.setPosition(0);
    FView.byId('HeaderFooterLayout').modifier.setTransform(Transform.translate(0, DRAG_LIMIT_TOP - displacement, 20));
  }
});

I can't get the same method to work using FlexScrollview. Instead of _displacement I can use .getAbsolutePosition(). The problem has to do with setPosition(0). With the regular Scrollview, you can use this function even when dragging. With FlexScrollview, _scroll.particle.setPosition(0) works, but you see the effect only when you stop dragging, which doesn't work as you still get the "overscroll" effect before you stop dragging. Disabling the "overscroll" in options get's rid of the effect, but you lose the offset values you need to move the HeaderFooterLayout down.

I'll probably post a gif if the effect is hard to visualize.

IjzerenHein commented 9 years ago

Yes please post a gif and if possible also a live demo. Cheers

Wenape commented 9 years ago

Demo: http://f-drawer.meteor.com/ (Use Chrome to emulate touch, works crappy with mouse scroll) Repo: https://github.com/Wenape/drawer-example Gif:

IjzerenHein commented 9 years ago

Hi, is this something that could work for you? http://gloey.nl/apps/leadingScrollViewDelegate (just inspect the source using the browser)

It uses the LeadingScrollView feature through implementing a delegate which implements several functions. The delegate resizes the headerfooterLayout accordingly.

Wenape commented 9 years ago

Works for me, also nice to have the extra functions. Thanks.