n4kz / react-native-pages

Easy to use page view component
Other
376 stars 83 forks source link

scrollToPage doesn't work when animated = false #54

Open tadasstra opened 3 years ago

tadasstra commented 3 years ago

scrollToPage doesn't work when animated = false. That happens because of this:

requestAnimationFrame(() => {
        this.scrollToPage(Math.floor(this.progress), false);
});

After scrollToPage it calls scrollToPage second time and goes back to 0 page.

Quick hack to override this issue (hopefully we can see a fix next version and we don't need this dirty hack):

//Set scrollState to 1 before scrolling
pager.current.scrollState = 1;
pager.current.scrollToPage(0, false)

//Make scrollState to 0 zero after scroll will finish
setTimeout(() => {
      pager.current.scrollState = 0
}, 100)

Thanks!!!