Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

onPageScrolled returns zeros when scrolling between first and last item #4

Open
stevep99 opened this issue Dec 4, 2013 · 1 comment

Comments

@stevep99
Copy link

stevep99 commented Dec 4, 2013

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.

@imbryk
Copy link
Owner

imbryk commented Apr 8, 2014

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 ;) )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants