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

Commit 6d28c900 authored by omarmt's avatar omarmt
Browse files

MultiPointerDraggableNode checks orientation only once

Test: Just a refactor
Bug: 345434452
Flag: com.android.systemui.scene_container
Change-Id: I03ffcd8f20ee5834999da6fa66110045d139d4e7
parent a93c960d
Loading
Loading
Loading
Loading
+15 −7
Original line number Diff line number Diff line
@@ -138,11 +138,26 @@ internal class MultiPointerDraggableNode(
            }
        }

    private var _toFloat = orientation.toFunctionOffsetToFloat()

    private fun Offset.toFloat(): Float = _toFloat(this)

    private fun Orientation.toFunctionOffsetToFloat(): (Offset) -> Float =
        when (this) {
            Orientation.Vertical -> {
                { it.y }
            }
            Orientation.Horizontal -> {
                { it.x }
            }
        }

    var orientation: Orientation = orientation
        set(value) {
            // Reset the pointer input whenever orientation changed.
            if (value != field) {
                field = value
                _toFloat = field.toFunctionOffsetToFloat()
                delegate.resetPointerInputHandler()
            }
        }
@@ -367,13 +382,6 @@ internal class MultiPointerDraggableNode(
        return event
    }

    private fun Offset.toFloat(): Float {
        return when (orientation) {
            Orientation.Vertical -> y
            Orientation.Horizontal -> x
        }
    }

    /**
     * Continues to read drag events until all pointers are up or the drag event is canceled. The
     * initial pointer to use for driving the drag is [initialPointerId]. [hasDragged] passes the