Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disabling automatic carousel transitions on user interaction #4914

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -80,17 +80,26 @@ class FtueAuthSplashCarouselFragment @Inject constructor(
"Branch: ${BuildConfig.GIT_BRANCH_NAME}"
views.loginSplashVersion.debouncedClicks { navigator.openDebug(requireContext()) }
}
views.splashCarousel.registerAutomaticUntilInteractionTransitions()
}

private fun ViewPager2.registerAutomaticUntilInteractionTransitions() {
var scheduledTransition: Job? = null
registerOnPageChangeCallback(object : ViewPager2.OnPageChangeCallback() {
private var hasUserManuallyInteractedWithCarousel: Boolean = false

views.splashCarousel.apply {
var scheduledTransition: Job? = null
registerOnPageChangeCallback(object : ViewPager2.OnPageChangeCallback() {
override fun onPageSelected(position: Int) {
scheduledTransition?.cancel()
override fun onPageScrolled(position: Int, positionOffset: Float, positionOffsetPixels: Int) {
hasUserManuallyInteractedWithCarousel = !isFakeDragging
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we check if the scroll was performed by a fake drag, if so we infer that it was the automatic transition and allow the next transition to be scheduled

}

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 {