Skip to content

Commit dd331c9

Browse files
committed
Improve readability of canReachTargetWithDecay with if-else
1 parent 6e93efc commit dd331c9

1 file changed

Lines changed: 7 additions & 11 deletions

File tree

JetLagged/app/src/main/java/com/example/jetlagged/JetLaggedDrawer.kt

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -158,17 +158,13 @@ fun HomeScreenDrawer(windowSizeClass: WindowSizeClass) {
158158
} else {
159159
0f
160160
}
161-
val canReachTargetWithDecay =
162-
(
163-
targetOffsetX > actualTargetX &&
164-
velocity > 0f &&
165-
actualTargetX > 0f
166-
) ||
167-
(
168-
targetOffsetX < actualTargetX &&
169-
velocity < 0 &&
170-
actualTargetX == 0f
171-
)
161+
val canReachTargetWithDecay = if (actualTargetX > 0f) {
162+
// We are aiming for the open state, check if the fling is strong enough to overshoot.
163+
velocity > 0f && targetOffsetX > actualTargetX
164+
} else {
165+
// We are aiming for the closed state, check if the fling is strong enough to overshoot.
166+
velocity < 0f && targetOffsetX < actualTargetX
167+
}
172168
if (canReachTargetWithDecay) {
173169
translationX.animateDecay(
174170
initialVelocity = velocity,

0 commit comments

Comments
 (0)