overscroll-decor icon indicating copy to clipboard operation
overscroll-decor copied to clipboard

SwipeToRefreshLayout and overscroll of RecyclerView

Open orcchg opened this issue 7 years ago • 3 comments

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?

orcchg avatar Aug 08 '17 14:08 orcchg

+1

rlazar avatar Sep 05 '17 20:09 rlazar

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

MinaMak avatar Jun 27 '18 11:06 MinaMak

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
   ...
}

forceporquillo avatar Aug 21 '21 17:08 forceporquillo