Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import android.support.v7.widget.RecyclerView
/**
* @author drakeet
*/
class QuickReturnDelegate(private val scrollSlop: Int = 12) : RecyclerView.OnScrollListener() {
private lateinit var callback: (hide: Boolean) -> Unit
private var scrollY: Int = 0
fun attach(recyclerView: RecyclerView, callback: (hide: Boolean) -> Unit) {
this.callback = callback
recyclerView.addOnScrollListener(this)
}
override fun onScrollStateChanged(recyclerView: RecyclerView?, newState: Int) {
if (newState == RecyclerView.SCROLL_STATE_IDLE) {
scrollY = 0
}
}
override fun onScrolled(recyclerView: RecyclerView?, dx: Int, dy: Int) {
scrollY += dy
callback(scrollY > scrollSlop)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.