fix: reset gesture state on touchcancel - #834
Open
NemeZZiZZ wants to merge 1 commit into
Open
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.
Problem
When the system cancels an in-progress touch gesture (incoming call overlay, notification
shade, palm rejection, browser gesture takeover), a
touchcancelevent is fired instead oftouchend. Currently it is almost unhandled:src/common/EventHandler.ts:692— atouchcancellistener on the target only clears thelong-tap timeout.
touchmove/touchendlisteners (subscribed on touch start, unsubscribedon touch end) are not removed on cancel.
_activeTouchId,_touchMoveStartCoordinate) is not reset, and the chartlevel (
Event) never learns the gesture is over.After a cancelled gesture the handler stays in the "finger down" state: the next touch has
to untangle stale listeners/state, and dragging/scrolling state started on the chart
(
_startScrollCoordinate, axis scale state, crosshair) is left dangling — the chart cankeep behaving as if the finger is still down.
Fix
Handle
touchcancelsymmetrically totouchend:src/common/EventHandler.tstouchCancelEventto theEventHandlerinterface._touchCancelHandler: resolves the active touch, resets_activeTouchId,_lastTouchEventTimeStamp,_touchMoveStartCoordinate, unsubscribes the root touchlisteners, marks the gesture so it cannot resolve into a tap, and dispatches
touchCancelEvent.touchcanceltogether withtouchmove/touchendon the rootelement (
{ passive: false }).src/Event.tstouchCancelEvent(e): sendsmouseUpEventto the widget under the finger (sowidgets that started a pressed interaction release it), then unconditionally resets the
scroll/scale gesture state (same set as
touchEndEvent) plus the touch-specific state(
_touchCoordinate,_touchCancelCrosshair,_touchZoomed) and clears the crosshair.Unlike
touchEndEvent, the state reset is unconditional: on cancel there is nomeaningful "widget under the finger" semantics to gate on, and the point of the handler is
to guarantee a clean slate.
Verification
pnpm code-lint— pass (154 files, no fixes)pnpm type-check— passpnpm build-esm— passpull) mid-gesture — afterwards the chart responds to the next touch immediately and no
crosshair/scroll state is stuck; on
mainthe same sequence leaves the gesture statedangling.
Notes
touchEndEvent), so no changeis needed there.
touchcancellistener for the long-tap timeout is kept.