mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2025-02-27 19:19:25 +03:00
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
1 changed files with 3 additions and 1 deletions
|
@ -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…
Add table
Reference in a new issue