Skip to content
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