Unverified Commit 7f02566c authored by Tong Mu's avatar Tong Mu Committed by GitHub

Add "OneSequenceRecognizer.resolvePointer". Fix DragGestureRecognizer crash on...

Add "OneSequenceRecognizer.resolvePointer". Fix DragGestureRecognizer crash on multiple pointers (#39017)

* Add drag tests

* Add resolvePointer

* Correct monodrag implementation

* Fix some addTearDown
parent 74076958
......@@ -251,8 +251,7 @@ abstract class DragGestureRecognizer extends OneSequenceGestureRecognizer {
if (event is PointerMoveEvent) {
if (event.buttons != _initialButtons) {
resolve(GestureDisposition.rejected);
stopTrackingPointer(event.pointer);
_giveUpPointer(event.pointer);
return;
}
if (_state == _DragState.accepted) {
......@@ -278,7 +277,12 @@ abstract class DragGestureRecognizer extends OneSequenceGestureRecognizer {
resolve(GestureDisposition.accepted);
}
}
stopTrackingIfPointerNoLongerDown(event);
if (event is PointerUpEvent || event is PointerCancelEvent) {
_giveUpPointer(
event.pointer,
reject: event is PointerCancelEvent || _state ==_DragState.possible,
);
}
}
@override
......@@ -325,7 +329,7 @@ abstract class DragGestureRecognizer extends OneSequenceGestureRecognizer {
@override
void rejectGesture(int pointer) {
stopTrackingPointer(pointer);
_giveUpPointer(pointer);
}
@override
......@@ -349,6 +353,16 @@ abstract class DragGestureRecognizer extends OneSequenceGestureRecognizer {
_state = _DragState.ready;
}
void _giveUpPointer(int pointer, {bool reject = true}) {
stopTrackingPointer(pointer);
if (reject) {
if (_velocityTrackers.containsKey(pointer)) {
_velocityTrackers.remove(pointer);
resolvePointer(pointer, GestureDisposition.rejected);
}
}
}
void _checkDown() {
assert(_initialButtons == kPrimaryButton);
final DragDownDetails details = DragDownDetails(
......
......@@ -255,6 +255,18 @@ abstract class OneSequenceGestureRecognizer extends GestureRecognizer {
entry.resolve(disposition);
}
/// Resolves this recognizer's participation in the given gesture arena with
/// the given disposition.
@protected
@mustCallSuper
void resolvePointer(int pointer, GestureDisposition disposition) {
final GestureArenaEntry entry = _entries[pointer];
if (entry != null) {
entry.resolve(disposition);
_entries.remove(pointer);
}
}
@override
void dispose() {
resolve(GestureDisposition.rejected);
......
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