imbryk/LoopingViewPager

onPageScrolled returns zeros when scrolling between first and last item

Opened this issue · 1 comments

LoopViewPager.onPageScrolled(...) has some logic whereby if the user scrolls left from the first item (i.e. looping across the first-last item boundary), then onPageScrolled returns zeros.

if (realPosition != mAdapter.getRealCount() - 1) {
    mOuterPageChangeListener.onPageScrolled(realPosition,
            positionOffset, positionOffsetPixels);
} else {
    if (positionOffset > .5) {
        mOuterPageChangeListener.onPageScrolled(0, 0, 0);
    } else {
        mOuterPageChangeListener.onPageScrolled(realPosition,
                0, 0);
    }
}

In my case I am scaling items depending on scroll position, but the problem would occur when anyone wants to use the onPageScrolled values. Basically whatever code logic the developer implements in his own onPageScrolled, this logic will fail when scroll transitions between first and last item in the list.

I have fixed this by having LoopViewPager.onPageScrolled always calling

mOuterPageChangeListener.onPageScrolled(realPosition,
                            positionOffset, positionOffsetPixels);

(i.e. removing the "if"-logic).

Is there are reason for the "if"-logic? Seems better to me to always return scroll values here.

I see your point, and it's completely valid - I added the "if" as I was using with circle pager indicator, and without the zeros last circle was going outside.
Probably it would be reasonable to allow user to set a flag if he wants to receive actual values between first and last element.
I will have a second look at this in spare time (which I don't usually have ;) )