Unverified Commit 8ddfc80c authored by leo's avatar leo Committed by GitHub

fix resampling leads to Hard to tap (#81022)

* fix PointerUpEvent conversion PointerMoveEvent needs to use the default buttons value.(#73286)

* feat PointerMoveEvent conversion adds test cases

* fix event conversion may modify the original buttons value.

* Update packages/flutter/lib/src/gestures/resampler.dart
Co-authored-by: 's avatarDavid Reveman <dreveman@gmail.com>
parent 275ba5e3
......@@ -42,12 +42,14 @@ class PointerEventResampler {
bool _isTracked = false;
bool _isDown = false;
int _pointerIdentifier = 0;
int _hasButtons = 0;
PointerEvent _toHoverEvent(
PointerEvent event,
Offset position,
Offset delta,
Duration timeStamp,
int buttons,
) {
return PointerHoverEvent(
timeStamp: timeStamp,
......@@ -79,6 +81,7 @@ class PointerEventResampler {
Offset delta,
int pointerIdentifier,
Duration timeStamp,
int buttons,
) {
return PointerMoveEvent(
timeStamp: timeStamp,
......@@ -87,7 +90,7 @@ class PointerEventResampler {
device: event.device,
position: position,
delta: delta,
buttons: event.buttons,
buttons: buttons,
obscured: event.obscured,
pressure: event.pressure,
pressureMin: event.pressureMin,
......@@ -113,9 +116,12 @@ class PointerEventResampler {
int pointerIdentifier,
Duration timeStamp,
bool isDown,
int buttons,
) {
return isDown ? _toMoveEvent(event, position, delta, pointerIdentifier, timeStamp)
: _toHoverEvent(event, position, delta, timeStamp);
return isDown
? _toMoveEvent(
event, position, delta, pointerIdentifier, timeStamp, buttons)
: _toHoverEvent(event, position, delta, timeStamp, buttons);
}
Offset _positionAt(Duration sampleTime) {
......@@ -205,10 +211,12 @@ class PointerEventResampler {
final bool wasTracked = _isTracked;
final bool wasDown = _isDown;
final int hadButtons = _hasButtons;
// Update pointer state.
_isTracked = event is! PointerRemovedEvent;
_isDown = event.down;
_hasButtons = event.buttons;
// Position at `sampleTime`.
final Offset position = _positionAt(sampleTime);
......@@ -235,7 +243,8 @@ class PointerEventResampler {
// therefor never produce `hover` events.
if (position != _position) {
final Offset delta = position - _position;
callback(_toMoveOrHoverEvent(event, position, delta, _pointerIdentifier, sampleTime, wasDown));
callback(_toMoveOrHoverEvent(event, position, delta,
_pointerIdentifier, sampleTime, wasDown, hadButtons));
_position = position;
}
callback(event.copyWith(
......@@ -261,7 +270,8 @@ class PointerEventResampler {
final PointerEvent? next = _next;
if (position != _position && next != null) {
final Offset delta = position - _position;
callback(_toMoveOrHoverEvent(next, position, delta, _pointerIdentifier, sampleTime, _isDown));
callback(_toMoveOrHoverEvent(next, position, delta, _pointerIdentifier,
sampleTime, _isDown, _hasButtons));
_position = position;
}
}
......
......@@ -153,6 +153,8 @@ void main() {
expect(result[4].position.dy, 15.0);
expect(result[4].delta.dx, 10.0);
expect(result[4].delta.dy, -10.0);
// buttons field needs to be a valid value
expect(result[4].buttons, kPrimaryButton);
expect(result[5].timeStamp, const Duration(microseconds: 4500));
expect(result[5] is PointerUpEvent, true);
expect(result[5].position.dx, 35.0);
......
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