WheelPicker stops between two items when fling is interrupted by touch#184
Open
daihieptn97 wants to merge 3 commits intodevaige:mainfrom
Open
WheelPicker stops between two items when fling is interrupted by touch#184daihieptn97 wants to merge 3 commits intodevaige:mainfrom
daihieptn97 wants to merge 3 commits intodevaige:mainfrom
Conversation
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.
Fix: WheelPicker stops between two items when fling is interrupted by touch
Problem
When the user swipes the wheel strongly (triggering a fling), then immediately taps the wheel to stop it, the picker halts at an intermediate position between two items. As a result:
OnItemSelectedListeneris not triggered)This happens because
ACTION_DOWNcallsscroller.abortAnimation(), which stops the scroll immediately at whateverscrollOffsetYvalue the fling was at — without snapping to the nearest item boundary. When the finger lifts (ACTION_UP), the event is treated as a click (isClick = true), so the snap logic inside theACTION_UPblock is never executed.Root Cause
In
onTouchEvent, theACTION_DOWNbranch:After
abortAnimation(),scrollOffsetYcan be a value like347whenitemHeightis100, leaving the wheel stuck 47px between two items. Since the subsequentACTION_UPdetects a tap (not a scroll), it skips the snap logic entirely.Fix
After calling
scroller.abortAnimation()inACTION_DOWN, immediately correctscrollOffsetYto the nearest item boundary using the existingcomputeDistanceToEndPoint()helper:Why this approach
computeDistanceToEndPoint()method — no new logic introducedcoerceIn) already used inACTION_UPfor non-cyclic modeinvalidate()so the wheel visually snaps before the user lifts their fingerSteps to Reproduce
OnItemSelectedListenerTesting
Tested on:
No regressions observed in normal tap, slow scroll, or fast fling scenarios.