disabling user input whilst the automatic animation is taking place, fixes crashes when user input is attempted at the same time
This commit is contained in:
parent
bdb41b253d
commit
a0bda02824
@ -27,7 +27,7 @@ fun ViewPager2.setCurrentItem(
|
|||||||
item: Int,
|
item: Int,
|
||||||
duration: Long,
|
duration: Long,
|
||||||
interpolator: TimeInterpolator = AccelerateDecelerateInterpolator(),
|
interpolator: TimeInterpolator = AccelerateDecelerateInterpolator(),
|
||||||
pagePxWidth: Int = width // Default value taken from getWidth() from ViewPager2 view
|
pagePxWidth: Int = width,
|
||||||
) {
|
) {
|
||||||
val pxToDrag: Int = pagePxWidth * (item - currentItem)
|
val pxToDrag: Int = pagePxWidth * (item - currentItem)
|
||||||
val animator = ValueAnimator.ofInt(0, pxToDrag)
|
val animator = ValueAnimator.ofInt(0, pxToDrag)
|
||||||
@ -47,10 +47,12 @@ fun ViewPager2.setCurrentItem(
|
|||||||
}
|
}
|
||||||
animator.addListener(object : Animator.AnimatorListener {
|
animator.addListener(object : Animator.AnimatorListener {
|
||||||
override fun onAnimationStart(animation: Animator?) {
|
override fun onAnimationStart(animation: Animator?) {
|
||||||
|
isUserInputEnabled = false
|
||||||
beginFakeDrag()
|
beginFakeDrag()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onAnimationEnd(animation: Animator?) {
|
override fun onAnimationEnd(animation: Animator?) {
|
||||||
|
isUserInputEnabled = true
|
||||||
endFakeDrag()
|
endFakeDrag()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user