Created
April 29, 2020 06:08
-
-
Save BalazsErik/6bcd2019befe42b2df028caef94124c8 to your computer and use it in GitHub Desktop.
This file contains 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
inline fun ViewPager2.onPageSelected(lifecycleOwner: LifecycleOwner, | |
crossinline listener: (position: Int) -> Unit) { | |
object : OnPageChangeCallback() { | |
override fun onPageSelected(position: Int) = listener(position) | |
}.let { | |
LifecycleEventDispatcher(lifecycleOwner, | |
onStart = { registerOnPageChangeCallback(it) }, | |
onStop = { unregisterOnPageChangeCallback(it) }) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment