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

PullToRefresh banner gets locked when scrolling quickly #42

Open
jmgirven opened this issue Apr 4, 2014 · 1 comment
Open

PullToRefresh banner gets locked when scrolling quickly #42

jmgirven opened this issue Apr 4, 2014 · 1 comment

Comments

@jmgirven
Copy link

jmgirven commented Apr 4, 2014

I have a similar problem to issue #40, loosing the ability to pull to refresh. It is possibly the same bug. I found a consistent way to reproduce it in my app was to:

  • Load a fresh page (therefore at the top of the list).
  • "Fling" scroll towards the bottom of the list
  • Before the previous "fling" scroll downwards has finished, "fling" back to the top of the page.
  • Finally, try to pull to refresh.

If you don't know what I mean by "fling", see onFling at http://developer.android.com/reference/android/view/GestureDetector.OnGestureListener.html . It is a fast scroll and release. The page continues to scroll even though your finger has left the page.

Looking at the code, the reason the refresh is not happening is that in PullToRefreshListView -- onTouchEvent, ACTION_MOVE is being called but previousY==-1. The first if statement therefore does not pass.

The difference between the above method and this:

  • Fresh page
  • Fling down
  • Wait for fling to finish
  • Fling to top
  • Pull to refresh (successful)

is that ACTION_DOWN is not called in the latter case, but is in the former, setting previousY = -1. I believe the ACTION_DOWN code is there for the purpose of stopping a user performing a pull to refresh unless they have started their pull from the top of the list. I think this makes sense.

My solution to this issue is to include:

previousY = event.getY();

to ACTION_UP, just before the break statement, outside of the if.

case MotionEvent.ACTION_UP:
    if(previousY != -1 && (state == State.RELEASE_TO_REFRESH || getFirstVisiblePosition() == 0)){
        switch(state){
            case RELEASE_TO_REFRESH:
                setState(State.REFRESHING);
                bounceBackHeader();

                break;

            case PULL_TO_REFRESH:
                resetHeader();
                break;
        }
    }
    previousY = event.getY(); // --- HERE ---
    break;

I am not sure if there will be unintended consequences to this. I have started testing and it seems to work. I will keep you posted.

@androidlearners
Copy link

Thanks for your nice work! It solves my problem .

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