diff options
| author | 2024-06-07 15:56:35 +0000 | |
|---|---|---|
| committer | 2024-06-13 13:52:06 +0000 | |
| commit | 6d28c9007ed4efecefc36629e0cd5435fdf3ab5c (patch) | |
| tree | cff6a57d855b3d566b8a6bac5f5150994ec8854b | |
| parent | a93c960d61256882d74ed7b03f671d8bc2de9af2 (diff) | |
MultiPointerDraggableNode checks orientation only once
Test: Just a refactor
Bug: 345434452
Flag: com.android.systemui.scene_container
Change-Id: I03ffcd8f20ee5834999da6fa66110045d139d4e7
| -rw-r--r-- | packages/SystemUI/compose/scene/src/com/android/compose/animation/scene/MultiPointerDraggable.kt | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/packages/SystemUI/compose/scene/src/com/android/compose/animation/scene/MultiPointerDraggable.kt b/packages/SystemUI/compose/scene/src/com/android/compose/animation/scene/MultiPointerDraggable.kt index 6001f1fd6db0..572b1d7ab670 100644 --- a/packages/SystemUI/compose/scene/src/com/android/compose/animation/scene/MultiPointerDraggable.kt +++ b/packages/SystemUI/compose/scene/src/com/android/compose/animation/scene/MultiPointerDraggable.kt @@ -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 |