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

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

Merge "SwipeSourceDetector.source() should return SwipeSource.Resolved" into main

parents 1c6f1389 7ae41a81
Loading
Loading
Loading
Loading
+6 −8
Original line number Diff line number Diff line
@@ -190,14 +190,12 @@ internal class DraggableHandlerImpl(
    private fun computeSwipes(startedPosition: Offset?, pointersDown: Int): Swipes {
        val fromSource =
            startedPosition?.let { position ->
                layoutImpl.swipeSourceDetector
                    .source(
                layoutImpl.swipeSourceDetector.source(
                    layoutImpl.lastSize,
                    position.round(),
                    layoutImpl.density,
                    orientation,
                )
                    ?.resolve(layoutImpl.layoutDirection)
            }

        val upOrLeft =
+7 −7
Original line number Diff line number Diff line
@@ -54,23 +54,23 @@ class FixedSizeEdgeDetector(val size: Dp) : SwipeSourceDetector {
        position: IntOffset,
        density: Density,
        orientation: Orientation,
    ): Edge? {
    ): Edge.Resolved? {
        val axisSize: Int
        val axisPosition: Int
        val topOrLeft: Edge
        val bottomOrRight: Edge
        val topOrLeft: Edge.Resolved
        val bottomOrRight: Edge.Resolved
        when (orientation) {
            Orientation.Horizontal -> {
                axisSize = layoutSize.width
                axisPosition = position.x
                topOrLeft = Edge.Left
                bottomOrRight = Edge.Right
                topOrLeft = Edge.Resolved.Left
                bottomOrRight = Edge.Resolved.Right
            }
            Orientation.Vertical -> {
                axisSize = layoutSize.height
                axisPosition = position.y
                topOrLeft = Edge.Top
                bottomOrRight = Edge.Bottom
                topOrLeft = Edge.Resolved.Top
                bottomOrRight = Edge.Resolved.Bottom
            }
        }

+1 −1
Original line number Diff line number Diff line
@@ -475,7 +475,7 @@ interface SwipeSourceDetector {
        position: IntOffset,
        density: Density,
        orientation: Orientation,
    ): SwipeSource?
    ): SwipeSource.Resolved?
}

/** The result of performing a [UserAction]. */
+4 −4
Original line number Diff line number Diff line
@@ -33,7 +33,7 @@ import kotlin.math.abs
 * SwipeSourceDetector} to enable fullscreen swipe handling to transition to and from the glanceable
 * hub.
 */
class CommunalSwipeDetector(private var lastDirection: SwipeSource? = null) :
class CommunalSwipeDetector(private var lastDirection: SwipeSource.Resolved? = null) :
    SwipeSourceDetector, SwipeDetector {
    companion object {
        private const val TRAVEL_RATIO_THRESHOLD = .5f
@@ -44,15 +44,15 @@ class CommunalSwipeDetector(private var lastDirection: SwipeSource? = null) :
        position: IntOffset,
        density: Density,
        orientation: Orientation
    ): SwipeSource? {
    ): SwipeSource.Resolved? {
        return lastDirection
    }

    override fun detectSwipe(change: PointerInputChange): Boolean {
        if (change.positionChange().x > 0) {
            lastDirection = Edge.Left
            lastDirection = Edge.Resolved.Left
        } else {
            lastDirection = Edge.Right
            lastDirection = Edge.Resolved.Right
        }

        // Determine whether the ratio of the distance traveled horizontally to the distance
+10 −10
Original line number Diff line number Diff line
@@ -34,7 +34,7 @@ class FixedSizeEdgeDetectorTest {

    @Test
    fun horizontalEdges() {
        fun horizontalEdge(position: Int): Edge? =
        fun horizontalEdge(position: Int): Edge.Resolved? =
            detector.source(
                layoutSize,
                position = IntOffset(position, 0),
@@ -42,17 +42,17 @@ class FixedSizeEdgeDetectorTest {
                Orientation.Horizontal,
            )

        assertThat(horizontalEdge(0)).isEqualTo(Edge.Left)
        assertThat(horizontalEdge(30)).isEqualTo(Edge.Left)
        assertThat(horizontalEdge(0)).isEqualTo(Edge.Resolved.Left)
        assertThat(horizontalEdge(30)).isEqualTo(Edge.Resolved.Left)
        assertThat(horizontalEdge(31)).isEqualTo(null)
        assertThat(horizontalEdge(69)).isEqualTo(null)
        assertThat(horizontalEdge(70)).isEqualTo(Edge.Right)
        assertThat(horizontalEdge(100)).isEqualTo(Edge.Right)
        assertThat(horizontalEdge(70)).isEqualTo(Edge.Resolved.Right)
        assertThat(horizontalEdge(100)).isEqualTo(Edge.Resolved.Right)
    }

    @Test
    fun verticalEdges() {
        fun verticalEdge(position: Int): Edge? =
        fun verticalEdge(position: Int): Edge.Resolved? =
            detector.source(
                layoutSize,
                position = IntOffset(0, position),
@@ -60,11 +60,11 @@ class FixedSizeEdgeDetectorTest {
                Orientation.Vertical,
            )

        assertThat(verticalEdge(0)).isEqualTo(Edge.Top)
        assertThat(verticalEdge(30)).isEqualTo(Edge.Top)
        assertThat(verticalEdge(0)).isEqualTo(Edge.Resolved.Top)
        assertThat(verticalEdge(30)).isEqualTo(Edge.Resolved.Top)
        assertThat(verticalEdge(31)).isEqualTo(null)
        assertThat(verticalEdge(69)).isEqualTo(null)
        assertThat(verticalEdge(70)).isEqualTo(Edge.Bottom)
        assertThat(verticalEdge(100)).isEqualTo(Edge.Bottom)
        assertThat(verticalEdge(70)).isEqualTo(Edge.Resolved.Bottom)
        assertThat(verticalEdge(100)).isEqualTo(Edge.Resolved.Bottom)
    }
}