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: David Reveman <dreveman@gmail.com>
This commit is contained in:
parent
275ba5e3c8
commit
8ddfc80c7f
@ -42,12 +42,14 @@ class PointerEventResampler {
|
|||||||
bool _isTracked = false;
|
bool _isTracked = false;
|
||||||
bool _isDown = false;
|
bool _isDown = false;
|
||||||
int _pointerIdentifier = 0;
|
int _pointerIdentifier = 0;
|
||||||
|
int _hasButtons = 0;
|
||||||
|
|
||||||
PointerEvent _toHoverEvent(
|
PointerEvent _toHoverEvent(
|
||||||
PointerEvent event,
|
PointerEvent event,
|
||||||
Offset position,
|
Offset position,
|
||||||
Offset delta,
|
Offset delta,
|
||||||
Duration timeStamp,
|
Duration timeStamp,
|
||||||
|
int buttons,
|
||||||
) {
|
) {
|
||||||
return PointerHoverEvent(
|
return PointerHoverEvent(
|
||||||
timeStamp: timeStamp,
|
timeStamp: timeStamp,
|
||||||
@ -79,6 +81,7 @@ class PointerEventResampler {
|
|||||||
Offset delta,
|
Offset delta,
|
||||||
int pointerIdentifier,
|
int pointerIdentifier,
|
||||||
Duration timeStamp,
|
Duration timeStamp,
|
||||||
|
int buttons,
|
||||||
) {
|
) {
|
||||||
return PointerMoveEvent(
|
return PointerMoveEvent(
|
||||||
timeStamp: timeStamp,
|
timeStamp: timeStamp,
|
||||||
@ -87,7 +90,7 @@ class PointerEventResampler {
|
|||||||
device: event.device,
|
device: event.device,
|
||||||
position: position,
|
position: position,
|
||||||
delta: delta,
|
delta: delta,
|
||||||
buttons: event.buttons,
|
buttons: buttons,
|
||||||
obscured: event.obscured,
|
obscured: event.obscured,
|
||||||
pressure: event.pressure,
|
pressure: event.pressure,
|
||||||
pressureMin: event.pressureMin,
|
pressureMin: event.pressureMin,
|
||||||
@ -113,9 +116,12 @@ class PointerEventResampler {
|
|||||||
int pointerIdentifier,
|
int pointerIdentifier,
|
||||||
Duration timeStamp,
|
Duration timeStamp,
|
||||||
bool isDown,
|
bool isDown,
|
||||||
|
int buttons,
|
||||||
) {
|
) {
|
||||||
return isDown ? _toMoveEvent(event, position, delta, pointerIdentifier, timeStamp)
|
return isDown
|
||||||
: _toHoverEvent(event, position, delta, timeStamp);
|
? _toMoveEvent(
|
||||||
|
event, position, delta, pointerIdentifier, timeStamp, buttons)
|
||||||
|
: _toHoverEvent(event, position, delta, timeStamp, buttons);
|
||||||
}
|
}
|
||||||
|
|
||||||
Offset _positionAt(Duration sampleTime) {
|
Offset _positionAt(Duration sampleTime) {
|
||||||
@ -205,10 +211,12 @@ class PointerEventResampler {
|
|||||||
|
|
||||||
final bool wasTracked = _isTracked;
|
final bool wasTracked = _isTracked;
|
||||||
final bool wasDown = _isDown;
|
final bool wasDown = _isDown;
|
||||||
|
final int hadButtons = _hasButtons;
|
||||||
|
|
||||||
// Update pointer state.
|
// Update pointer state.
|
||||||
_isTracked = event is! PointerRemovedEvent;
|
_isTracked = event is! PointerRemovedEvent;
|
||||||
_isDown = event.down;
|
_isDown = event.down;
|
||||||
|
_hasButtons = event.buttons;
|
||||||
|
|
||||||
// Position at `sampleTime`.
|
// Position at `sampleTime`.
|
||||||
final Offset position = _positionAt(sampleTime);
|
final Offset position = _positionAt(sampleTime);
|
||||||
@ -235,7 +243,8 @@ class PointerEventResampler {
|
|||||||
// therefor never produce `hover` events.
|
// therefor never produce `hover` events.
|
||||||
if (position != _position) {
|
if (position != _position) {
|
||||||
final Offset delta = 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;
|
_position = position;
|
||||||
}
|
}
|
||||||
callback(event.copyWith(
|
callback(event.copyWith(
|
||||||
@ -261,7 +270,8 @@ class PointerEventResampler {
|
|||||||
final PointerEvent? next = _next;
|
final PointerEvent? next = _next;
|
||||||
if (position != _position && next != null) {
|
if (position != _position && next != null) {
|
||||||
final Offset delta = position - _position;
|
final Offset delta = position - _position;
|
||||||
callback(_toMoveOrHoverEvent(next, position, delta, _pointerIdentifier, sampleTime, _isDown));
|
callback(_toMoveOrHoverEvent(next, position, delta, _pointerIdentifier,
|
||||||
|
sampleTime, _isDown, _hasButtons));
|
||||||
_position = position;
|
_position = position;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -153,6 +153,8 @@ void main() {
|
|||||||
expect(result[4].position.dy, 15.0);
|
expect(result[4].position.dy, 15.0);
|
||||||
expect(result[4].delta.dx, 10.0);
|
expect(result[4].delta.dx, 10.0);
|
||||||
expect(result[4].delta.dy, -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].timeStamp, const Duration(microseconds: 4500));
|
||||||
expect(result[5] is PointerUpEvent, true);
|
expect(result[5] is PointerUpEvent, true);
|
||||||
expect(result[5].position.dx, 35.0);
|
expect(result[5].position.dx, 35.0);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user