Yalantis / Phoenix

Phoenix Pull-to-Refresh
https://yalantis.com/
Apache License 2.0
4.02k stars 920 forks source link

Issue while using RecyclerView instead of ListView #1

Closed SanthoshDhandapani closed 9 years ago

SanthoshDhandapani commented 9 years ago

If i try to scroll up from the bottom of the list, it pulls the refresh view instead of scrolling up. Please fix it asap.

SanthoshDhandapani commented 9 years ago

I just love your work. Please fix this issue asap, so that this will become very effective.

shliama commented 9 years ago

@SanthoshDhandapani thanks for reporting a bug. Unfortunately I couldn't reproduce it. Can you post a screenshot or video of how/to reproduce it step by step. Also I've created a branch (issue_1) which has sample that uses RecyclerView instead of ListView. Thanks in advance.

SanthoshDhandapani commented 9 years ago

@shliama Thank you very much for the response and sorry for my unclear steps about the issue. You sample project was working absolutely file. The issue happens when we place a view group under the pull to refresh view. Like the below screenshot rsz_pullto In my project i need to do something with the help of relative layout, so in this case it happens.

shliama commented 9 years ago

@SanthoshDhandapani ok, now it's clear. I'll try to find out the way to fix this issue asap. Excuse me for delayed response, I'm quite busy these days.

SanthoshDhandapani commented 9 years ago

Thanks for your response dude. Take your own time.

shliama commented 9 years ago

@SanthoshDhandapani ok, I've reproduced the problem, and found the solution. The problem was in the PullToRefreshView.java class in method canChildScrollUp(). The thing is, there is also a method called ensureTarget() which looks for a child view (in your case, it is RelativeLayout), that's why canChildScrollUp() was always returning false.

So, I recommend you to include this library to your project as local library project and change ensureTarget() method for your needs. Something similar to this (that is working with above code on your screenshot, but a bit ugly ;)

All changes are in PullToRefreshView class.
    /** Create new variable to keep your list view that scrolls */
    private View mListTarget;

    private void ensureTarget() {
        if (mTarget != null)
            return;
        if (getChildCount() > 0) {
            for (int i = 0; i < getChildCount(); i++) {
                View child = getChildAt(i);
                if (child != mRefreshView) {
                    mTarget = child;

                    /** Add here your logic to find it, here is just sample to take 1st child */
                    if (child instanceof ViewGroup) {
                        mListTarget = ((ViewGroup) child).getChildAt(0);
                    }
                }
            }
        }
    }

    /** Pass here not the whole child, but sub-child that scrolls */
    private boolean canChildScrollUp() {
        return ViewCompat.canScrollVertically(mListTarget, -1);
    }
SanthoshDhandapani commented 9 years ago

@shilama Thank you very much for your efforts.