Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 305de0b3 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "STL skipAnimation should depends on canChangeContent" into main

parents 2935e9a9 fb219458
Loading
Loading
Loading
Loading
+8 −7
Original line number Diff line number Diff line
@@ -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)) {
@@ -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
+22 −1
Original line number Diff line number Diff line
@@ -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
@@ -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 {