compose-samples
compose-samples copied to clipboard
[Bug]: [JetLagged] canReachTargetWithDecay Condition will always be false in JetLaggedDrawer.kt
Is there an existing issue for this?
- [X] I have searched the existing issues
Is there a StackOverflow question about this issue?
- [X] I have searched StackOverflow
Is this an issue related to one of the samples?
- [X] Yes, this is a specific issue related to this samples repo.
Sample app
Other (bug not related to sample app)
What happened?
In Jetlagged we have JetLaggedDrawer.kt
val targetDifference = (actualTargetX - targetOffsetX)
val canReachTargetWithDecay =
(
targetOffsetX > actualTargetX && velocity > 0f &&
targetDifference > 0f
) ||
(
targetOffsetX < actualTargetX && velocity < 0 &&
targetDifference < 0f
)
If we check the code we can see that canReachTargetWithDecay
will always be false and the reason is if targetOffsetX
is greater than actualTargetX
(which either be 0 or drawerWidth) then targetDifference
will always in negative (<0) but in the first condition of last check targetDifference > 0f
which always be <0 hence the result will be false and same goes for the second condition if targetOffsetX
is smaller then targetDifference
will always >0f (positive) hence second condition will always be false.
Because of this, the running conditions of different animation methods will also be not required
if (canReachTargetWithDecay) {
translationX.animateDecay(
initialVelocity = velocity,
animationSpec = decay
)
} else {
translationX.animateTo(actualTargetX, initialVelocity = velocity)
}
I might be wrong here Please CMIMW @riggaroo
Related PR https://github.com/android/compose-samples/pull/1174
Relevant logcat output
No response
Code of Conduct
- [X] I agree to follow this project's Code of Conduct