Loading packages/SystemUI/compose/scene/src/com/android/compose/animation/scene/SwipeAnimation.kt +8 −7 Original line number Diff line number Diff line Loading @@ -337,13 +337,6 @@ internal class SwipeAnimation<T : ContentKey>( check(!isAnimatingOffset()) { "SwipeAnimation.animateOffset() can only be called once" } val initialProgress = progress // Skip the animation if we have already reached the target content and the overscroll does // not animate anything. val hasReachedTargetContent = (targetContent == toContent && initialProgress >= 1f) || (targetContent == fromContent && initialProgress <= 0f) val skipAnimation = hasReachedTargetContent && !contentTransition.isWithinProgressRange(initialProgress) val targetContent = if (targetContent != currentContent && !canChangeContent(targetContent)) { Loading @@ -352,6 +345,14 @@ internal class SwipeAnimation<T : ContentKey>( targetContent } // Skip the animation if we have already reached the target content and the overscroll does // not animate anything. val hasReachedTargetContent = (targetContent == toContent && initialProgress >= 1f) || (targetContent == fromContent && initialProgress <= 0f) val skipAnimation = hasReachedTargetContent && !contentTransition.isWithinProgressRange(initialProgress) val targetOffset = if (targetContent == fromContent) { 0f Loading packages/SystemUI/compose/scene/tests/src/com/android/compose/animation/scene/DraggableHandlerTest.kt +22 −1 Original line number Diff line number Diff line Loading @@ -42,7 +42,6 @@ import com.android.compose.animation.scene.content.state.TransitionState.Transit import com.android.compose.animation.scene.subjects.assertThat import com.android.compose.test.MonotonicClockTestScope import com.android.compose.test.runMonotonicClockTest import com.android.compose.test.transition import com.google.common.truth.Truth.assertThat import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Deferred Loading Loading @@ -920,6 +919,28 @@ class DraggableHandlerTest { assertIdle(SceneA) } @Test fun blockTransition_animated() = runGestureTest { assertIdle(SceneA) layoutState.transitions = transitions { overscrollDisabled(SceneB, Orientation.Vertical) } // Swipe up to scene B. Overscroll 50%. val dragController = onDragStarted(overSlop = up(1.5f), expectedConsumedOverSlop = up(1.0f)) assertTransition(currentScene = SceneA, fromScene = SceneA, toScene = SceneB, progress = 1f) // Block the transition when the user release their finger. canChangeScene = { false } val velocityConsumed = dragController.onDragStoppedAnimateLater(velocity = -velocityThreshold) // Start an animation: overscroll and from 1f to 0f. assertTransition(currentScene = SceneA, fromScene = SceneA, toScene = SceneB, progress = 1f) val consumed = velocityConsumed.await() assertThat(consumed).isEqualTo(-velocityThreshold) assertIdle(SceneA) } @Test fun scrollFromIdleWithNoTargetScene_shouldUseOverscrollSpecIfAvailable() = runGestureTest { layoutState.transitions = transitions { Loading Loading
packages/SystemUI/compose/scene/src/com/android/compose/animation/scene/SwipeAnimation.kt +8 −7 Original line number Diff line number Diff line Loading @@ -337,13 +337,6 @@ internal class SwipeAnimation<T : ContentKey>( check(!isAnimatingOffset()) { "SwipeAnimation.animateOffset() can only be called once" } val initialProgress = progress // Skip the animation if we have already reached the target content and the overscroll does // not animate anything. val hasReachedTargetContent = (targetContent == toContent && initialProgress >= 1f) || (targetContent == fromContent && initialProgress <= 0f) val skipAnimation = hasReachedTargetContent && !contentTransition.isWithinProgressRange(initialProgress) val targetContent = if (targetContent != currentContent && !canChangeContent(targetContent)) { Loading @@ -352,6 +345,14 @@ internal class SwipeAnimation<T : ContentKey>( targetContent } // Skip the animation if we have already reached the target content and the overscroll does // not animate anything. val hasReachedTargetContent = (targetContent == toContent && initialProgress >= 1f) || (targetContent == fromContent && initialProgress <= 0f) val skipAnimation = hasReachedTargetContent && !contentTransition.isWithinProgressRange(initialProgress) val targetOffset = if (targetContent == fromContent) { 0f Loading
packages/SystemUI/compose/scene/tests/src/com/android/compose/animation/scene/DraggableHandlerTest.kt +22 −1 Original line number Diff line number Diff line Loading @@ -42,7 +42,6 @@ import com.android.compose.animation.scene.content.state.TransitionState.Transit import com.android.compose.animation.scene.subjects.assertThat import com.android.compose.test.MonotonicClockTestScope import com.android.compose.test.runMonotonicClockTest import com.android.compose.test.transition import com.google.common.truth.Truth.assertThat import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Deferred Loading Loading @@ -920,6 +919,28 @@ class DraggableHandlerTest { assertIdle(SceneA) } @Test fun blockTransition_animated() = runGestureTest { assertIdle(SceneA) layoutState.transitions = transitions { overscrollDisabled(SceneB, Orientation.Vertical) } // Swipe up to scene B. Overscroll 50%. val dragController = onDragStarted(overSlop = up(1.5f), expectedConsumedOverSlop = up(1.0f)) assertTransition(currentScene = SceneA, fromScene = SceneA, toScene = SceneB, progress = 1f) // Block the transition when the user release their finger. canChangeScene = { false } val velocityConsumed = dragController.onDragStoppedAnimateLater(velocity = -velocityThreshold) // Start an animation: overscroll and from 1f to 0f. assertTransition(currentScene = SceneA, fromScene = SceneA, toScene = SceneB, progress = 1f) val consumed = velocityConsumed.await() assertThat(consumed).isEqualTo(-velocityThreshold) assertIdle(SceneA) } @Test fun scrollFromIdleWithNoTargetScene_shouldUseOverscrollSpecIfAvailable() = runGestureTest { layoutState.transitions = transitions { Loading