summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--packages/SystemUI/compose/scene/src/com/android/compose/animation/scene/MultiPointerDraggable.kt22
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