diff --git a/vector/src/main/java/im/vector/app/features/onboarding/ftueauth/FtueAuthSplashCarouselFragment.kt b/vector/src/main/java/im/vector/app/features/onboarding/ftueauth/FtueAuthSplashCarouselFragment.kt index 05295c5b8d..30416bde9e 100644 --- a/vector/src/main/java/im/vector/app/features/onboarding/ftueauth/FtueAuthSplashCarouselFragment.kt +++ b/vector/src/main/java/im/vector/app/features/onboarding/ftueauth/FtueAuthSplashCarouselFragment.kt @@ -22,6 +22,8 @@ import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import androidx.core.view.isVisible +import androidx.lifecycle.DefaultLifecycleObserver +import androidx.lifecycle.LifecycleOwner import androidx.lifecycle.lifecycleScope import androidx.viewpager2.widget.ViewPager2 import com.airbnb.mvrx.withState @@ -90,7 +92,7 @@ class FtueAuthSplashCarouselFragment @Inject constructor( private fun ViewPager2.registerAutomaticUntilInteractionTransitions() { var scheduledTransition: Job? = null - registerOnPageChangeCallback(object : ViewPager2.OnPageChangeCallback() { + val pageChangingCallback = object : ViewPager2.OnPageChangeCallback() { private var hasUserManuallyInteractedWithCarousel: Boolean = false override fun onPageScrolled(position: Int, positionOffset: Float, positionOffsetPixels: Int) { @@ -104,6 +106,15 @@ class FtueAuthSplashCarouselFragment @Inject constructor( scheduledTransition = scheduleCarouselTransition() } } + } + viewLifecycleOwner.lifecycle.addObserver(object : DefaultLifecycleObserver { + override fun onCreate(owner: LifecycleOwner) { + registerOnPageChangeCallback(pageChangingCallback) + } + + override fun onDestroy(owner: LifecycleOwner) { + unregisterOnPageChangeCallback(pageChangingCallback) + } }) }