Created
July 26, 2020 09:17
-
-
Save lukelorusso/44c0449d78666543367783e142092031 to your computer and use it in GitHub Desktop.
Second try: somehow, this is not enough...
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun RecyclerView.bindScrollTo(vararg destinations: RecyclerView) { | |
object : RecyclerView.OnScrollListener() { | |
override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) { | |
super.onScrollStateChanged(recyclerView, newState) | |
} | |
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) { | |
// when you scroll a RecyclerView of some [dx, dy] you can do it | |
super.onScrolled(recyclerView, dx, dy) | |
// and then, ONLY if this RecyclerView is NOT idle, you can propagate that scroll | |
// (this is to avoid infinite multiplications of [dx, dy] when calling scrollBy) | |
if (recyclerView.scrollState != RecyclerView.SCROLL_STATE_IDLE) | |
destinations.forEach { destinationRecyclerView -> | |
destinationRecyclerView.scrollBy(dx, dy) | |
} | |
// somehow, this is not enough... | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment