fix: use smoothed velocity direction for touch flings to prevent off-axis glides#2226
Open
JonasGrunau wants to merge 1 commit into
Open
fix: use smoothed velocity direction for touch flings to prevent off-axis glides#2226JonasGrunau wants to merge 1 commit into
JonasGrunau wants to merge 1 commit into
Conversation
…axis glides Since fleaflet#2158 the fling direction is derived from the single last tracked pointer segment. That fixed the pointer-leaves-window case on web/desktop, but on touch devices the last segment is dominated by sampling noise and lift-off thumb-roll, so fast swipes glide off-axis and repeated flicks visibly zigzag (fleaflet#2225). Prefer the gesture recognizer's velocity direction - a least-squares fit over the last ~100ms of samples - when the gesture came from a touch pointer, where the pointer cannot leave the window mid-drag. Mouse and trackpad input keep the tracked-segment behaviour from fleaflet#2158. Also negate the velocityDirection passed as the division-by-zero fallback (fleaflet#2220) so all three direction candidates share the tracked-offset sign convention; previously the degenerate case glided against the swipe. Fixes fleaflet#2225. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2225.
What
On touch input, derive the fling direction from the gesture recognizer's velocity (Flutter's
VelocityTracker, a least-squares fit over the last ~100 ms of samples) instead of the single last tracked pointer segment. Mouse/trackpad input keeps the tracked-segment behaviour introduced in #2158, which handles the pointer leaving the window mid-drag — a case that cannot occur with touch.Also negates the
velocityDirectionpassed intoflingDirection()as the division-by-zero fallback (#2220), so all three direction candidates share the tracked-offset sign convention (end: flingOffset + direction * distance). Previously the degenerate zero/zero case glided against the swipe, sincedetails.velocity.pixelsPerSecondpoints along the pointer motion whilefinalSegment/flingOffsetrun opposite to it (8.2.2 used the velocity with- direction * distance).Why
The last tracked segment is one frame-to-frame delta. At fast swipe speeds it is dominated by touch-sampling noise and lift-off thumb-roll, so its direction routinely deviates 30–90° from the swipe axis: fast flicks glide off-axis and repeated flicks visibly zigzag (see #2225 for the full analysis). The fitted velocity direction is stable — it's what the pre-8.3.0 fling used and what platform map apps use.
How
MapInteractiveViewerStaterecords the device kind of the last pointer-down.flingDirection()gains apreferVelocityDirectionparameter; when set (touch), the already-normalizedvelocityDirectionis returned directly, otherwise the existing preference order (final segment → overall drag offset → velocity fallback) is unchanged.flingDirectiontests updated for the new parameter; new test covers the touch preference.All existing tests pass (
flutter test),dart analyzeclean,dart formatclean.