aligning the carousel listener removal with the viewLifecycleOwner
- fixes crash where the scheduled callbacks can attempt to trigger after the view has been destroyed
This commit is contained in:
parent
a4b5d1819d
commit
c4834a44d1
|
@ -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)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue