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

Commit 24be01f1 authored by Jordan Demeulenaere's avatar Jordan Demeulenaere
Browse files

Intercepted transition keeps previous distance

This CL ensures that an intercepted transition remembers its previous
swipe distance. This ensures that a transition progress does not
instantly jump in case the user distance changed since it started.

Bug: 290930950
Test: atest DraggableHandlerTest
Flag: com.android.systemui.scene_container
Change-Id: I1395848fd798f9bfb123811ea328039092e0dc59
parent 076e6fc6
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -543,7 +543,8 @@ private fun SwipeTransition(old: SwipeTransition): SwipeTransition {
            _toScene = old._toScene,
            userActionDistanceScope = old.userActionDistanceScope,
            orientation = old.orientation,
            isUpOrLeft = old.isUpOrLeft
            isUpOrLeft = old.isUpOrLeft,
            lastDistance = old.lastDistance,
        )
        .apply {
            _currentScene = old._currentScene
@@ -561,6 +562,7 @@ private class SwipeTransition(
    val userActionDistanceScope: UserActionDistanceScope,
    override val orientation: Orientation,
    override val isUpOrLeft: Boolean,
    var lastDistance: Float = DistanceUnspecified,
) :
    TransitionState.Transition(_fromScene.key, _toScene.key),
    TransitionState.HasOverscrollProperties {
@@ -620,8 +622,6 @@ private class SwipeTransition(
                get() = distance().absoluteValue
        }

    private var lastDistance = DistanceUnspecified

    /** Whether [TransitionState.Transition.finish] was called on this transition. */
    var isFinishing = false
        private set
+1 −1
Original line number Diff line number Diff line
@@ -461,7 +461,7 @@ data class UserActionResult(
    val transitionKey: TransitionKey? = null,
)

interface UserActionDistance {
fun interface UserActionDistance {
    /**
     * Return the **absolute** distance of the user action given the size of the scene we are
     * animating from and the [orientation].
+19 −0
Original line number Diff line number Diff line
@@ -1195,4 +1195,23 @@ class DraggableHandlerTest {
        assertThat(transition).hasProgress(0f)
        assertThat(transition).hasOverscrollSpec()
    }

    @Test
    fun interceptingTransitionKeepsDistance() = runGestureTest {
        var swipeDistance = 75f
        layoutState.transitions = transitions {
            from(SceneA, to = SceneB) { distance = UserActionDistance { _, _ -> swipeDistance } }
        }

        // Start transition.
        val controller = onDragStarted(overSlop = -50f)
        assertTransition(fromScene = SceneA, toScene = SceneB, progress = 50f / 75f)

        // Intercept the transition and change the swipe distance. The original distance and
        // progress should be the same.
        swipeDistance = 50f
        controller.onDragStopped(0f)
        onDragStartedImmediately()
        assertTransition(fromScene = SceneA, toScene = SceneB, progress = 50f / 75f)
    }
}