Skip to content

Prevent pull-to-refresh for every touch of a multi-touch gesture - #228

Open
officialasishkumar wants to merge 1 commit into
hotwired:mainfrom
officialasishkumar:fix/multi-touch-pull-to-refresh
Open

officialasishkumar wants to merge 1 commit into
hotwired:mainfrom
officialasishkumar:fix/multi-touch-pull-to-refresh

Conversation

@officialasishkumar

Copy link
Copy Markdown

Fixes #206

The touch tracking behind data-native-prevent-pull-to-refresh (added in #98) only looked at the touch that triggered each event:

  • touchstart checked only the new finger's target, so a second finger landing outside a protected element overwrote the state with false.
  • touchend always cleared the state, even when another finger was still on the protected element.

After a two-finger pinch on a map, lifting one finger let HotwireSwipeRefreshLayout intercept the remaining finger's drag and trigger a refresh.

turbo.js now derives the state from all active touches. On every touchstart, touchend and touchcancel, it reports whether any remaining touch is on a scrollable or protected element, using the existing ancestor walk unchanged. When no touches remain, it reports the end of the touch. Handling touchcancel also stops the state from staying set after a canceled touch. Single-touch behavior is the same as before, and nothing changes on the native side apart from the doc comments on the two Session callbacks.

There's no JavaScript test setup in the repo, so I tested this by running turbo.js against a stubbed DOM with these touch sequences:

Sequence Before After
One finger on a protected element prevented prevented
Two fingers on it, lift one allowed prevented
One finger on it, a second finger elsewhere allowed prevented
…then lift the second finger allowed prevented
Touch canceled stays prevented allowed
Lift all fingers allowed allowed

The touch tracking behind data-native-prevent-pull-to-refresh only looked
at the touch that triggered each event. A second finger landing outside a
protected element overwrote the state with false, and lifting any finger
cleared it, even while another finger was still on the protected element.
The SwipeRefreshLayout could then intercept the remaining finger's drag,
e.g. after a two finger pinch on a map, and trigger a refresh.

Derive the state from all active touches instead. On every touchstart,
touchend and touchcancel, report whether any remaining touch is on a
scrollable or protected element, and report the end of the touch once no
touches remain. Handling touchcancel also stops the state from staying
set after a canceled touch.

Fixes hotwired#206
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Pull-to-refresh re-arms mid-gesture during multi-touch on elements with data-native-prevent-pull-to-refresh

1 participant