Loading packages/SystemUI/compose/scene/src/com/android/compose/animation/scene/SwipeAnimation.kt +11 −4 Original line number Diff line number Diff line Loading @@ -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) { Loading @@ -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 Loading packages/SystemUI/compose/scene/tests/src/com/android/compose/animation/scene/DraggableHandlerTest.kt +30 −0 Original line number Diff line number Diff line Loading @@ -772,6 +772,36 @@ class DraggableHandlerTest { assertThat(transition).hasProgress(1f) } @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 += Loading Loading
packages/SystemUI/compose/scene/src/com/android/compose/animation/scene/SwipeAnimation.kt +11 −4 Original line number Diff line number Diff line Loading @@ -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) { Loading @@ -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 Loading
packages/SystemUI/compose/scene/tests/src/com/android/compose/animation/scene/DraggableHandlerTest.kt +30 −0 Original line number Diff line number Diff line Loading @@ -772,6 +772,36 @@ class DraggableHandlerTest { assertThat(transition).hasProgress(1f) } @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 += Loading