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

Commit 59fa4013 authored by Jordan Demeulenaere's avatar Jordan Demeulenaere Committed by Android (Google) Code Review
Browse files

Merge "Intercepted transition keeps previous distance" into main

parents 238e14a0 24be01f1
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)
    }
}