Unverified Commit 27b306a3 authored by Jason Simmons's avatar Jason Simmons Committed by GitHub

Track used Android pointer IDs and reuse IDs after a pointer is released (#61668)

parent f8a82feb
...@@ -495,6 +495,7 @@ class _AndroidMotionEventConverter { ...@@ -495,6 +495,7 @@ class _AndroidMotionEventConverter {
<int, AndroidPointerCoords>{}; <int, AndroidPointerCoords>{};
final Map<int, AndroidPointerProperties> pointerProperties = final Map<int, AndroidPointerProperties> pointerProperties =
<int, AndroidPointerProperties>{}; <int, AndroidPointerProperties>{};
final Set<int> usedAndroidPointerIds = <int>{};
Offset Function(Offset position) _pointTransformer; Offset Function(Offset position) _pointTransformer;
...@@ -503,14 +504,18 @@ class _AndroidMotionEventConverter { ...@@ -503,14 +504,18 @@ class _AndroidMotionEventConverter {
_pointTransformer = transformer; _pointTransformer = transformer;
} }
int nextPointerId = 0;
int downTimeMillis; int downTimeMillis;
void handlePointerDownEvent(PointerDownEvent event) { void handlePointerDownEvent(PointerDownEvent event) {
if (nextPointerId == 0) { if (pointerProperties.isEmpty) {
downTimeMillis = event.timeStamp.inMilliseconds; downTimeMillis = event.timeStamp.inMilliseconds;
} }
pointerProperties[event.pointer] = propertiesFor(event, nextPointerId++); int androidPointerId = 0;
while (usedAndroidPointerIds.contains(androidPointerId)) {
androidPointerId++;
}
usedAndroidPointerIds.add(androidPointerId);
pointerProperties[event.pointer] = propertiesFor(event, androidPointerId);
} }
void updatePointerPositions(PointerEvent event) { void updatePointerPositions(PointerEvent event) {
...@@ -531,9 +536,9 @@ class _AndroidMotionEventConverter { ...@@ -531,9 +536,9 @@ class _AndroidMotionEventConverter {
void handlePointerUpEvent(PointerUpEvent event) { void handlePointerUpEvent(PointerUpEvent event) {
pointerPositions.remove(event.pointer); pointerPositions.remove(event.pointer);
usedAndroidPointerIds.remove(pointerProperties[event.pointer].id);
pointerProperties.remove(event.pointer); pointerProperties.remove(event.pointer);
if (pointerProperties.isEmpty) { if (pointerProperties.isEmpty) {
nextPointerId = 0;
downTimeMillis = null; downTimeMillis = null;
} }
} }
...@@ -541,7 +546,7 @@ class _AndroidMotionEventConverter { ...@@ -541,7 +546,7 @@ class _AndroidMotionEventConverter {
void handlePointerCancelEvent(PointerCancelEvent event) { void handlePointerCancelEvent(PointerCancelEvent event) {
pointerPositions.clear(); pointerPositions.clear();
pointerProperties.clear(); pointerProperties.clear();
nextPointerId = 0; usedAndroidPointerIds.clear();
downTimeMillis = null; downTimeMillis = null;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment