Prevent scrolling outside bounds in webtoon/vertical reading mode (#8821)

(cherry picked from commit 992bab4f7956740bafd8227b29958acebfaae64d)
This commit is contained in:
Verzaukeks 2023-01-15 00:38:52 +01:00 committed by Jobobby04
parent 740b3e4616
commit eff93b8e7c

View File

@ -119,7 +119,8 @@ class WebtoonRecyclerView @JvmOverloads constructor(
val scaleAnimator = ValueAnimator.ofFloat(fromRate, toRate) val scaleAnimator = ValueAnimator.ofFloat(fromRate, toRate)
scaleAnimator.addUpdateListener { animation -> scaleAnimator.addUpdateListener { animation ->
setScaleRate(animation.animatedValue as Float) currentScale = animation.animatedValue as Float
setScaleRate(currentScale)
} }
animatorSet.playTogether(translationXAnimator, translationYAnimator, scaleAnimator) animatorSet.playTogether(translationXAnimator, translationYAnimator, scaleAnimator)
animatorSet.duration = ANIMATOR_DURATION_TIME.toLong() animatorSet.duration = ANIMATOR_DURATION_TIME.toLong()
@ -135,26 +136,26 @@ class WebtoonRecyclerView @JvmOverloads constructor(
if (currentScale <= 1f) return false if (currentScale <= 1f) return false
val distanceTimeFactor = 0.4f val distanceTimeFactor = 0.4f
var newX: Float? = null val animatorSet = AnimatorSet()
var newY: Float? = null
if (velocityX != 0) { if (velocityX != 0) {
val dx = (distanceTimeFactor * velocityX / 2) val dx = (distanceTimeFactor * velocityX / 2)
newX = getPositionX(x + dx) val newX = getPositionX(x + dx)
val translationXAnimator = ValueAnimator.ofFloat(x, newX)
translationXAnimator.addUpdateListener { animation -> x = getPositionX(animation.animatedValue as Float) }
animatorSet.play(translationXAnimator)
} }
if (velocityY != 0 && (atFirstPosition || atLastPosition)) { if (velocityY != 0 && (atFirstPosition || atLastPosition)) {
val dy = (distanceTimeFactor * velocityY / 2) val dy = (distanceTimeFactor * velocityY / 2)
newY = getPositionY(y + dy) val newY = getPositionY(y + dy)
val translationYAnimator = ValueAnimator.ofFloat(y, newY)
translationYAnimator.addUpdateListener { animation -> y = getPositionY(animation.animatedValue as Float) }
animatorSet.play(translationYAnimator)
} }
animate() animatorSet.duration = 400
.apply { animatorSet.interpolator = DecelerateInterpolator()
newX?.let { x(it) } animatorSet.start()
newY?.let { y(it) }
}
.setInterpolator(DecelerateInterpolator())
.setDuration(400)
.start()
return true return true
} }