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

SwipeToRefreshLayout and overscroll of RecyclerView #46

Open
orcchg opened this issue Aug 8, 2017 · 3 comments
Open

SwipeToRefreshLayout and overscroll of RecyclerView #46

orcchg opened this issue Aug 8, 2017 · 3 comments

Comments

@orcchg
Copy link

orcchg commented Aug 8, 2017

If RecyclerView is nested to SwipeToRefreshLayout and has Overscroll applied to it, then swipe-to-refresh does not work at all, though overscroll is working. Is it possible to have both swipe-to-refresh and overscroll enabled simultaneously?

@rlazar
Copy link

rlazar commented Sep 5, 2017

+1

@MinaMak
Copy link

MinaMak commented Jun 27, 2018

decor.setOverScrollUpdateListener(new IOverScrollUpdateListener() {
@OverRide
public void onOverScrollUpdate(IOverScrollDecor decor, int state, float offset) {
if (offset > 0) {
isOverScrolled = true;
binding.layoutSwipeRefresh.setRefreshing(true);
} else {
if (isOverScrolled) onRefreshListener();
isOverScrolled = false;
}
}
});

I made it like this you can listen when the user will over scroll the recyclerview and then setRefreshing(true) of the swipeRefreshLayout

@forceporquillo
Copy link

forceporquillo commented Aug 21, 2021

Thanks for this @MinaMak, I've translated your implementation to Kotlin and for someone looking for a workaround. Hope this could help.

In Kotlin, we can achieve this using extension and high-order lambda functions.

fun RecyclerView.setupOverScrollSwipeInterceptor(
    isInterceptStarted: (Boolean, Int) -> Unit
) {
    var isScrolled = false
    OverScrollDecoratorHelper.setUpOverScroll(this, 0).apply {
        setOverScrollUpdateListener { _, state, offset ->
            if (offset > 0) {
                isScrolled = true
                isInterceptStarted(true, state)
            } else {
                if (isScrolled) {
                    isInterceptStarted(false, state)
                }
                isScrolled = false
            }
        }
    }
}

And call this with your RecyclerView instance.

myList.setupOverScrollSwipInterceptor { isScrolled, state -> {
   // do something with the state
   ...
}

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

4 participants