summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Treehugger Robot <android-test-infra-autosubmit@system.gserviceaccount.com> 2025-01-28 09:13:22 -0800
committer Android (Google) Code Review <android-gerrit@google.com> 2025-01-28 09:13:22 -0800
commit8006649e1c7657fad9c41da5c31535a054656076 (patch)
treef89634c6ff575c792fdea69652360847782ca3b7
parentfb66a2666a49c3d254a49c39c556b0011b9a9290 (diff)
parent281126cffbe75bd6ae6e3cfddd30228f77b3a239 (diff)
Merge "STL decay animation should only play if decayOffset exceeds targetOffset" into main
-rw-r--r--packages/SystemUI/compose/scene/src/com/android/compose/animation/scene/SwipeAnimation.kt15
-rw-r--r--packages/SystemUI/compose/scene/tests/src/com/android/compose/animation/scene/DraggableHandlerTest.kt30
2 files changed, 41 insertions, 4 deletions
diff --git a/packages/SystemUI/compose/scene/src/com/android/compose/animation/scene/SwipeAnimation.kt b/packages/SystemUI/compose/scene/src/com/android/compose/animation/scene/SwipeAnimation.kt
index cb0d33cf5205..90c45eec9630 100644
--- a/packages/SystemUI/compose/scene/src/com/android/compose/animation/scene/SwipeAnimation.kt
+++ b/packages/SystemUI/compose/scene/src/com/android/compose/animation/scene/SwipeAnimation.kt
@@ -403,11 +403,14 @@ internal class SwipeAnimation<T : ContentKey>(
initialValue = initialOffset,
)
+ // The decay animation should only play if decayOffset exceeds targetOffset.
+ val lowerBound = checkNotNull(animatable.lowerBound) { "No lower bound" }
+ val upperBound = checkNotNull(animatable.upperBound) { "No upper bound" }
val willDecayReachBounds =
- when {
- targetOffset > initialOffset -> decayOffset >= targetOffset
- targetOffset < initialOffset -> decayOffset <= targetOffset
- else -> true
+ when (targetOffset) {
+ lowerBound -> decayOffset <= lowerBound
+ upperBound -> decayOffset >= upperBound
+ else -> error("Target $targetOffset should be $lowerBound or $upperBound")
}
if (willDecayReachBounds) {
@@ -421,6 +424,10 @@ internal class SwipeAnimation<T : ContentKey>(
appendLine(" targetOffset=$targetOffset")
appendLine(" initialVelocity=$initialVelocity")
appendLine(" decayOffset=$decayOffset")
+ appendLine(
+ " animateDecay result: reason=${result.endReason} " +
+ "value=${result.endState.value} velocity=${result.endState.velocity}"
+ )
}
}
return initialVelocity - result.endState.velocity
diff --git a/packages/SystemUI/compose/scene/tests/src/com/android/compose/animation/scene/DraggableHandlerTest.kt b/packages/SystemUI/compose/scene/tests/src/com/android/compose/animation/scene/DraggableHandlerTest.kt
index 969003cb92f3..06e76d470a08 100644
--- a/packages/SystemUI/compose/scene/tests/src/com/android/compose/animation/scene/DraggableHandlerTest.kt
+++ b/packages/SystemUI/compose/scene/tests/src/com/android/compose/animation/scene/DraggableHandlerTest.kt
@@ -773,6 +773,36 @@ class DraggableHandlerTest {
}
@Test
+ fun startSwipeAnimationFromBound() = runGestureTest {
+ // Swipe down to go to SceneC.
+ mutableUserActionsA = mapOf(Swipe.Down to SceneC)
+
+ val dragController =
+ onDragStarted(
+ position = Offset(SCREEN_SIZE / 2f, SCREEN_SIZE / 2f),
+ // Swipe up.
+ overSlop = up(0.5f),
+ // Should be ignored.
+ expectedConsumedOverSlop = 0f,
+ )
+
+ val transition = assertThat(transitionState).isSceneTransition()
+ assertThat(transition).hasFromScene(SceneA)
+ assertThat(transition).hasToScene(SceneC)
+ assertThat(transition).hasProgress(0f)
+
+ // Swipe down, but not enough to go to SceneC.
+ dragController.onDragStoppedAnimateNow(
+ velocity = velocityThreshold - 0.01f,
+ onAnimationStart = {
+ assertTransition(fromScene = SceneA, toScene = SceneC, progress = 0f)
+ },
+ )
+
+ assertIdle(SceneA)
+ }
+
+ @Test
fun requireFullDistanceSwipe() = runGestureTest {
mutableUserActionsA +=
Swipe.Up to UserActionResult(SceneB, requiresFullDistanceSwipe = true)