Skip to content

Fix onPress event accidentally triggered while scrolling the page #997

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion packages/react-native-web/src/exports/Touchable/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -755,7 +755,14 @@ const TouchableMixin = {
(!hasLongPressHandler || // But either has no long handler
!this.touchableLongPressCancelsPress()); // or we're told to ignore it.

const shouldInvokePress = !IsLongPressingIn[curState] || pressIsLongButStillCallOnPress;
// Fix onPress event accidentally triggered while scrolling the page
const touchBank = e.touchHistory.touchBank[e.touchHistory.indexOfSingleActiveTouch];
const offset = Math.sqrt(Math.pow(touchBank.startPageX - touchBank.currentPageX, 2)
+ Math.pow(touchBank.startPageY - touchBank.currentPageY, 2));
const velocity = (offset / (touchBank.currentTimeStamp - touchBank.startTimeStamp)) * 1000;
const IsMissPressFromScroll = velocity > 100;

const shouldInvokePress = (!IsLongPressingIn[curState] && !IsMissPressFromScroll) || pressIsLongButStillCallOnPress;
if (shouldInvokePress && this.touchableHandlePress) {
if (!newIsHighlight && !curIsHighlight) {
// we never highlighted because of delay, but we should highlight now
Expand Down