fix: mobile, two fingers cale, no tapdown (#9856)

Signed-off-by: fufesou <linlong1266@gmail.com>
This commit is contained in:
fufesou 2024-11-07 22:36:56 +08:00 committed by GitHub
parent d0ef52e418
commit 6f0cb3b8c2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -84,6 +84,9 @@ class _RawTouchGestureDetectorRegionState
double _mouseScrollIntegral = 0; // mouse scroll speed controller double _mouseScrollIntegral = 0; // mouse scroll speed controller
double _scale = 1; double _scale = 1;
// Workaround tap down event when two fingers are used to scale(mobile)
TapDownDetails? _lastTapDownDetails;
PointerDeviceKind? lastDeviceKind; PointerDeviceKind? lastDeviceKind;
// For touch mode, onDoubleTap // For touch mode, onDoubleTap
@ -114,15 +117,13 @@ class _RawTouchGestureDetectorRegionState
if (handleTouch) { if (handleTouch) {
_lastPosOfDoubleTapDown = d.localPosition; _lastPosOfDoubleTapDown = d.localPosition;
// Desktop or mobile "Touch mode" // Desktop or mobile "Touch mode"
final isMoved = _lastTapDownDetails = d;
await ffi.cursorModel.move(d.localPosition.dx, d.localPosition.dy);
if (isMoved) {
await inputModel.tapDown(MouseButtons.left);
}
} }
} }
onTapUp(TapUpDetails d) async { onTapUp(TapUpDetails d) async {
final TapDownDetails? lastTapDownDetails = _lastTapDownDetails;
_lastTapDownDetails = null;
if (lastDeviceKind != PointerDeviceKind.touch) { if (lastDeviceKind != PointerDeviceKind.touch) {
return; return;
} }
@ -130,7 +131,10 @@ class _RawTouchGestureDetectorRegionState
final isMoved = final isMoved =
await ffi.cursorModel.move(d.localPosition.dx, d.localPosition.dy); await ffi.cursorModel.move(d.localPosition.dx, d.localPosition.dy);
if (isMoved) { if (isMoved) {
inputModel.tapUp(MouseButtons.left); if (lastTapDownDetails != null) {
await inputModel.tapDown(MouseButtons.left);
}
await inputModel.tapUp(MouseButtons.left);
} }
} }
} }
@ -179,9 +183,7 @@ class _RawTouchGestureDetectorRegionState
if (handleTouch) { if (handleTouch) {
_lastPosOfDoubleTapDown = d.localPosition; _lastPosOfDoubleTapDown = d.localPosition;
_cacheLongPressPosition = d.localPosition; _cacheLongPressPosition = d.localPosition;
final isMoved = if (!ffi.cursorModel.isInRemoteRect(d.localPosition)) {
await ffi.cursorModel.move(d.localPosition.dx, d.localPosition.dy);
if (!isMoved) {
return; return;
} }
_cacheLongPressPositionTs = DateTime.now().millisecondsSinceEpoch; _cacheLongPressPositionTs = DateTime.now().millisecondsSinceEpoch;
@ -268,11 +270,17 @@ class _RawTouchGestureDetectorRegionState
} }
onOneFingerPanStart(BuildContext context, DragStartDetails d) async { onOneFingerPanStart(BuildContext context, DragStartDetails d) async {
final TapDownDetails? lastTapDownDetails = _lastTapDownDetails;
_lastTapDownDetails = null;
lastDeviceKind = d.kind ?? lastDeviceKind; lastDeviceKind = d.kind ?? lastDeviceKind;
if (lastDeviceKind != PointerDeviceKind.touch) { if (lastDeviceKind != PointerDeviceKind.touch) {
return; return;
} }
if (handleTouch) { if (handleTouch) {
if (lastTapDownDetails != null) {
await ffi.cursorModel.move(lastTapDownDetails.localPosition.dx,
lastTapDownDetails.localPosition.dy);
}
if (ffi.cursorModel.shouldBlock(d.localPosition.dx, d.localPosition.dy)) { if (ffi.cursorModel.shouldBlock(d.localPosition.dx, d.localPosition.dy)) {
return; return;
} }
@ -336,6 +344,7 @@ class _RawTouchGestureDetectorRegionState
// scale + pan event // scale + pan event
onTwoFingerScaleStart(ScaleStartDetails d) { onTwoFingerScaleStart(ScaleStartDetails d) {
_lastTapDownDetails = null;
if (lastDeviceKind != PointerDeviceKind.touch) { if (lastDeviceKind != PointerDeviceKind.touch) {
return; return;
} }