Merge pull request #4914 from vector-im/feature/adm/ftue-carousel-disable-automatic-transitions

Disabling automatic carousel transitions on user interaction
This commit is contained in:
Adam Brown 2022-01-13 11:03:05 +00:00 committed by GitHub
commit 807ceb74ad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 17 additions and 8 deletions

View File

@ -80,17 +80,26 @@ 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()
// only schedule automatic transitions whilst the user has not interacted with the carousel
if (!hasUserManuallyInteractedWithCarousel) {
scheduledTransition = scheduleCarouselTransition()
}
})
scheduledTransition = scheduleCarouselTransition()
}
}
})
}
private fun ViewPager2.scheduleCarouselTransition(): Job {