disabling the automatic carousel transitions on user interaction

- extracts all the logic to its own extension
This commit is contained in:
Adam Brown 2022-01-11 16:54:37 +00:00
parent 67bdf4b226
commit 672d4e591c
1 changed files with 18 additions and 8 deletions

View File

@ -80,17 +80,27 @@ class FtueAuthSplashCarouselFragment @Inject constructor(
"Branch: ${BuildConfig.GIT_BRANCH_NAME}"
views.loginSplashVersion.debouncedClicks { navigator.openDebug(requireContext()) }
}
views.splashCarousel.registerAutomaticUntilInteractionTransitions()
}
views.splashCarousel.apply {
var scheduledTransition: Job? = null
registerOnPageChangeCallback(object : ViewPager2.OnPageChangeCallback() {
override fun onPageSelected(position: Int) {
scheduledTransition?.cancel()
private fun ViewPager2.registerAutomaticUntilInteractionTransitions() {
var scheduledTransition: Job? = null
registerOnPageChangeCallback(object : ViewPager2.OnPageChangeCallback() {
private var hasUserManuallyInteractedWithCarousel: Boolean = false
override fun onPageScrolled(position: Int, positionOffset: Float, positionOffsetPixels: Int) {
hasUserManuallyInteractedWithCarousel = !isFakeDragging
}
override fun onPageSelected(position: Int) {
scheduledTransition?.cancel()
if (hasUserManuallyInteractedWithCarousel) {
// stop the automatic transitions
} else {
scheduledTransition = scheduleCarouselTransition()
}
})
scheduledTransition = scheduleCarouselTransition()
}
}
})
}
private fun ViewPager2.scheduleCarouselTransition(): Job {