From e3408625bcd96f5db09af50040301c223c7f2241 Mon Sep 17 00:00:00 2001 From: Nick Fisher Date: Wed, 11 Oct 2023 15:09:32 +0800 Subject: [PATCH] gesture updates for mobile --- .../filament_gesture_detector_mobile.dart | 42 +++++++++++-------- 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/lib/widgets/filament_gesture_detector_mobile.dart b/lib/widgets/filament_gesture_detector_mobile.dart index 4d1b1072..c00f98fe 100644 --- a/lib/widgets/filament_gesture_detector_mobile.dart +++ b/lib/widgets/filament_gesture_detector_mobile.dart @@ -110,6 +110,7 @@ class _FilamentGestureDetectorMobileState } Timer? _scrollTimer; + double _lastScale = 0; // pinch zoom on mobile // couldn't find any equivalent for pointerCount in Listener so we use two widgets: @@ -133,33 +134,26 @@ class _FilamentGestureDetectorMobileState onScaleStart: (d) async { if (d.pointerCount == 2) { _scaling = true; - widget.controller.zoomBegin(); + await widget.controller.zoomBegin(); } else if (!_scaling) { if (_rotateOnPointerMove) { - widget.controller - .rotateStart(d.focalPoint.dx, d.focalPoint.dy); + widget.controller.rotateStart( + d.localFocalPoint.dx, d.localFocalPoint.dy); } else { widget.controller - .panStart(d.focalPoint.dx, d.focalPoint.dy); - } - } - }, - onScaleEnd: (d) async { - if (d.pointerCount == 2) { - widget.controller.zoomEnd(); - _scaling = false; - } else if (!_scaling) { - if (_rotateOnPointerMove) { - widget.controller.rotateEnd(); - } else { - widget.controller.panEnd(); + .panStart(d.localFocalPoint.dx, d.localFocalPoint.dy); } } }, onScaleUpdate: (ScaleUpdateDetails d) async { if (d.pointerCount == 2) { - widget.controller.zoomUpdate(d.localFocalPoint.dx, - d.localFocalPoint.dy, d.horizontalScale > 1 ? 0.1 : -0.1); + if (d.horizontalScale != _lastScale) { + widget.controller.zoomUpdate( + d.localFocalPoint.dx, + d.localFocalPoint.dy, + d.horizontalScale > _lastScale ? 0.1 : -0.1); + _lastScale = d.horizontalScale; + } } else if (!_scaling) { if (_rotateOnPointerMove) { widget.controller @@ -170,6 +164,18 @@ class _FilamentGestureDetectorMobileState } } }, + onScaleEnd: (d) async { + if (d.pointerCount == 2) { + widget.controller.zoomEnd(); + } else if (!_scaling) { + if (_rotateOnPointerMove) { + widget.controller.rotateEnd(); + } else { + widget.controller.panEnd(); + } + } + _scaling = false; + }, child: widget.child)), widget.showControlOverlay ? Align(