Repository navigation
Conversation
On Android a snapping one-axis pan picked its point from a velocity tracker that only ever saw move events. A finger held still and then lifted kept the speed of its last move, so a drag let go short of halfway still flung on to the next point. The drag now also notes when the finger lifts, in the Initial pass so it is known before the detector ends the drag. If the last move was more than 40ms before the lift it lets go with no velocity, which is how Android's own VelocityTracker treats the up event. Co-Authored-By: Claude Opus 5.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.
On Android, a snapping one-axis pan (
pan-x-snap/pan-y-snap) could fling to the next point even when the finger had stopped before it lifted. Found in the dev-null image viewer (NativePHP/dev-null-app#175), whose drag to close is apan-ysnapping to[-far, 0, far]: drag down, hold still for a moment, let go short of halfway, and it closed instead of springing back.What was wrong
The snap picks its point from the velocity the drag lets go with. That velocity came from a Compose
VelocityTrackerfed only the move events the drag detectors pass on. A finger held still sends no moves, and the detectors end the drag without handing over the up event, so the tracker never learned the finger had stopped. It reported the speed of the last move however long the pause was.The fix
A small
ReleaseVelocitywraps the tracker in the snap path. Alongside the drag detector, the pan now watches for the finger lifting, in the Initial pass so the lift time is known before the detector ends the drag on the same event. If the last move was more than 40ms before the lift, the drag lets go with no velocity. That is the same rule Android's ownVelocityTrackerapplies when it gets the up event. The watcher only runs when an axis snaps, so other pans are untouched.Most of the renderer diff is the
whenblock moving one indent level into acoroutineScope. It reads much smaller with whitespace hidden. The change stays out of the lines #220 edits, and the branch merges with it cleanly.Testing
New
GestureAreaSnapTestin the Robolectric module, with a paragraph intests/android/README.md:main(it lands on 600).The whole module passes (79 tests).
iOS
iOS has the same problem, at least in the simulator. I checked with a throwaway SwiftUI app that attaches a one-finger
UIPanGestureRecognizerthroughUIGestureRecognizerRepresentable, asAxisPanRecognizerdoes, and an XCUITest that drags at 1500pt/s and then holds before lifting (iPhone 18 Pro simulator, iOS 27.0).velocity(in:)at.endedmatched the last.changedevery time: after holds of 0, 100ms, 300ms and 1s it reported 1394, 1360, 1403 and 1369 pt/s. UIKit doesn't decay it during the hold.So
AxisPanRecognizerhands the snap a stale velocity as well. On a real device a finger may jitter enough during a hold to send small moves that pull the velocity down, but I haven't checked that on hardware. This PR leaves iOS alone. The same check (time from the last move to the lift) would fit inAxisPanRecognizer's.ended.🤖 Generated with Claude Code