diff options
| author | 2024-09-27 15:11:02 +0000 | |
|---|---|---|
| committer | 2024-09-27 16:39:56 +0000 | |
| commit | 1e34a1dfac75048f0dfc93196c0e18f4f2a80132 (patch) | |
| tree | 1d6f5e78eed32cbd1f1c6b0591b7a0758bafebb4 | |
| parent | 19861d84ce36d0274ce49cdbb5e1f60f7ab66573 (diff) | |
Extract resolveSwipeSource() and resolveSwipe()
This will allow us to compute the Swipe.Resolved in a single point
Test: Just a refactor
Bug: 366387626
Flag: com.android.systemui.scene_container
Change-Id: I1ce5ae94b1def4cdfd2eff9b8e0d60162b230fff
| -rw-r--r-- | packages/SystemUI/compose/scene/src/com/android/compose/animation/scene/DraggableHandler.kt | 69 |
1 files changed, 39 insertions, 30 deletions
diff --git a/packages/SystemUI/compose/scene/src/com/android/compose/animation/scene/DraggableHandler.kt b/packages/SystemUI/compose/scene/src/com/android/compose/animation/scene/DraggableHandler.kt index 9891025ad7d3..367faed7b7f7 100644 --- a/packages/SystemUI/compose/scene/src/com/android/compose/animation/scene/DraggableHandler.kt +++ b/packages/SystemUI/compose/scene/src/com/android/compose/animation/scene/DraggableHandler.kt @@ -188,38 +188,47 @@ internal class DraggableHandlerImpl( return createSwipeAnimation(layoutImpl, result, isUpOrLeft, orientation) } - private fun computeSwipes(startedPosition: Offset?, pointersDown: Int): Swipes { - val fromSource = - startedPosition?.let { position -> - layoutImpl.swipeSourceDetector.source( - layoutImpl.lastSize, - position.round(), - layoutImpl.density, - orientation, - ) - } + private fun resolveSwipeSource(startedPosition: Offset?): SwipeSource.Resolved? { + if (startedPosition == null) return null + return layoutImpl.swipeSourceDetector.source( + layoutSize = layoutImpl.lastSize, + position = startedPosition.round(), + density = layoutImpl.density, + orientation = orientation, + ) + } - val upOrLeft = - Swipe.Resolved( - direction = - when (orientation) { - Orientation.Horizontal -> SwipeDirection.Resolved.Left - Orientation.Vertical -> SwipeDirection.Resolved.Up - }, - pointerCount = pointersDown, - fromSource = fromSource, - ) + private fun resolveSwipe( + pointersDown: Int, + fromSource: SwipeSource.Resolved?, + isUpOrLeft: Boolean, + ): Swipe.Resolved { + return Swipe.Resolved( + direction = + when (orientation) { + Orientation.Horizontal -> + if (isUpOrLeft) { + SwipeDirection.Resolved.Left + } else { + SwipeDirection.Resolved.Right + } - val downOrRight = - Swipe.Resolved( - direction = - when (orientation) { - Orientation.Horizontal -> SwipeDirection.Resolved.Right - Orientation.Vertical -> SwipeDirection.Resolved.Down - }, - pointerCount = pointersDown, - fromSource = fromSource, - ) + Orientation.Vertical -> + if (isUpOrLeft) { + SwipeDirection.Resolved.Up + } else { + SwipeDirection.Resolved.Down + } + }, + pointerCount = pointersDown, + fromSource = fromSource, + ) + } + + private fun computeSwipes(startedPosition: Offset?, pointersDown: Int): Swipes { + val fromSource = resolveSwipeSource(startedPosition) + val upOrLeft = resolveSwipe(pointersDown, fromSource, isUpOrLeft = true) + val downOrRight = resolveSwipe(pointersDown, fromSource, isUpOrLeft = false) return if (fromSource == null) { Swipes( |