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

Commit a280ccf8 authored by Jordan Demeulenaere's avatar Jordan Demeulenaere
Browse files

Add UserActionResult.requiresFullDistanceSwipe

Bug: 308961608
Test: atest DraggableHandlerTest
Flag: com.android.systemui.scene_container
Change-Id: Ie790b2e66d97d9e9e8d7911c18e6f101a899073f
parent d7996dbf
Loading
Loading
Loading
Loading
+12 −3
Original line number Diff line number Diff line
@@ -395,10 +395,11 @@ private class DragControllerImpl(
            if (
                distance != DistanceUnspecified &&
                    shouldCommitSwipe(
                        offset,
                        distance,
                        velocity,
                        offset = offset,
                        distance = distance,
                        velocity = velocity,
                        wasCommitted = swipeTransition._currentScene == toScene,
                        requiresFullDistanceSwipe = swipeTransition.requiresFullDistanceSwipe,
                    )
            ) {
                targetScene = toScene
@@ -472,7 +473,12 @@ private class DragControllerImpl(
        distance: Float,
        velocity: Float,
        wasCommitted: Boolean,
        requiresFullDistanceSwipe: Boolean,
    ): Boolean {
        if (requiresFullDistanceSwipe && !wasCommitted) {
            return offset / distance >= 1f
        }

        fun isCloserToTarget(): Boolean {
            return (offset - distance).absoluteValue < offset.absoluteValue
        }
@@ -530,6 +536,7 @@ private fun SwipeTransition(
        userActionDistanceScope = layoutImpl.userActionDistanceScope,
        orientation = orientation,
        isUpOrLeft = isUpOrLeft,
        requiresFullDistanceSwipe = result.requiresFullDistanceSwipe,
    )
}

@@ -545,6 +552,7 @@ private fun SwipeTransition(old: SwipeTransition): SwipeTransition {
            orientation = old.orientation,
            isUpOrLeft = old.isUpOrLeft,
            lastDistance = old.lastDistance,
            requiresFullDistanceSwipe = old.requiresFullDistanceSwipe,
        )
        .apply {
            _currentScene = old._currentScene
@@ -562,6 +570,7 @@ private class SwipeTransition(
    val userActionDistanceScope: UserActionDistanceScope,
    override val orientation: Orientation,
    override val isUpOrLeft: Boolean,
    val requiresFullDistanceSwipe: Boolean,
    var lastDistance: Float = DistanceUnspecified,
) :
    TransitionState.Transition(_fromScene.key, _toScene.key),
+7 −0
Original line number Diff line number Diff line
@@ -459,6 +459,13 @@ data class UserActionResult(

    /** The key of the transition that should be used. */
    val transitionKey: TransitionKey? = null,

    /**
     * If `true`, the swipe will be committed and we will settle to [toScene] if only if the user
     * swiped at least the swipe distance, i.e. the transition progress was already equal to or
     * bigger than 100% when the user released their finger. `
     */
    val requiresFullDistanceSwipe: Boolean = false,
)

fun interface UserActionDistance {
+18 −0
Original line number Diff line number Diff line
@@ -1215,4 +1215,22 @@ class DraggableHandlerTest {
        onDragStartedImmediately()
        assertTransition(fromScene = SceneA, toScene = SceneB, progress = 50f / 75f)
    }

    @Test
    fun requireFullDistanceSwipe() = runGestureTest {
        mutableUserActionsA[Swipe.Up] = UserActionResult(SceneB, requiresFullDistanceSwipe = true)

        val controller = onDragStarted(overSlop = up(fractionOfScreen = 0.9f))
        assertTransition(fromScene = SceneA, toScene = SceneB, progress = 0.9f)

        controller.onDragStopped(velocity = 0f)
        advanceUntilIdle()
        assertIdle(SceneA)

        val otherController = onDragStarted(overSlop = up(fractionOfScreen = 1f))
        assertTransition(fromScene = SceneA, toScene = SceneB, progress = 1f)
        otherController.onDragStopped(velocity = 0f)
        advanceUntilIdle()
        assertIdle(SceneB)
    }
}