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

Commit ebff7c8e authored by omarmt's avatar omarmt
Browse files

Track velocity of velocityPointerId only if is present

In case of multiple events with 0 pointers down (not pressed) we may
have already removed the velocityPointer.

Test: Rerun: atest MultiPointerDraggableTest
Bug: 367175475
Flag: com.android.systemui.scene_container
Change-Id: I8ee2030ec6154d844e994fe83a873e9a5910cd00
parent 39f0cf6e
Loading
Loading
Loading
Loading
+10 −2
Original line number Diff line number Diff line
@@ -51,6 +51,7 @@ import androidx.compose.ui.unit.IntSize
import androidx.compose.ui.unit.Velocity
import androidx.compose.ui.util.fastAll
import androidx.compose.ui.util.fastAny
import androidx.compose.ui.util.fastFilter
import androidx.compose.ui.util.fastFirstOrNull
import androidx.compose.ui.util.fastSumBy
import com.android.compose.ui.util.SpaceVectorConverter
@@ -234,8 +235,15 @@ internal class MultiPointerDraggableNode(
                    pointersDown == 0 -> {
                        startedPosition = null

                        val lastPointerUp = changes.single { it.id == velocityPointerId }
                        velocityTracker.addPointerInputChange(lastPointerUp)
                        // In case of multiple events with 0 pointers down (not pressed) we may have
                        // already removed the velocityPointer
                        val lastPointerUp = changes.fastFilter { it.id == velocityPointerId }
                        check(lastPointerUp.isEmpty() || lastPointerUp.size == 1) {
                            "There are ${lastPointerUp.size} pointers up: $lastPointerUp"
                        }
                        if (lastPointerUp.size == 1) {
                            velocityTracker.addPointerInputChange(lastPointerUp.first())
                        }
                    }

                    // The first pointer down, startedPosition was not set.