Skip to content

Commit 1e3eb7f

Browse files
committed
Undesirable onPress on mobile browsers scrolling fix
Canceling a event by moving outside from the Touchable area would not prevent the onPress event of being triggered This would affect users clicking on a Touchable by accident while scrolling up or down on mobile browsers It is probably a fix for the issue necolas#731
1 parent 73b459e commit 1e3eb7f

File tree

1 file changed

+10
-3
lines changed
  • packages/react-native-web/src/exports/Touchable

1 file changed

+10
-3
lines changed

packages/react-native-web/src/exports/Touchable/index.js

+10-3
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,7 @@ const TouchableMixin = {
386386
* Place as callback for a DOM element's `onResponderGrant` event.
387387
*/
388388
touchableHandleResponderGrant: function(e: Event) {
389+
this.preventOnPressTrigger = false;
389390
const dispatchID = e.currentTarget;
390391
// Since e is used in a callback invoked on another event loop
391392
// (as in setTimeout etc), we need to call e.persist() on the
@@ -448,6 +449,7 @@ const TouchableMixin = {
448449
// Not enough time elapsed yet, wait for highlight -
449450
// this is just a perf optimization.
450451
if (this.state.touchable.touchState === States.RESPONDER_INACTIVE_PRESS_IN) {
452+
this.preventOnPressTrigger = true;
451453
return;
452454
}
453455

@@ -690,7 +692,10 @@ const TouchableMixin = {
690692
}
691693
},
692694

693-
_cancelLongPressDelayTimeout: function() {
695+
_cancelLongPressDelayTimeout: function(preventOnPressTrigger: boolean = true) {
696+
if (preventOnPressTrigger) {
697+
this.preventOnPressTrigger = true;
698+
}
694699
this.longPressDelayTimeout && clearTimeout(this.longPressDelayTimeout);
695700
this.longPressDelayTimeout = null;
696701
},
@@ -740,7 +745,7 @@ const TouchableMixin = {
740745
signal === Signals.RESPONDER_TERMINATED || signal === Signals.RESPONDER_RELEASE;
741746

742747
if (isFinalSignal) {
743-
this._cancelLongPressDelayTimeout();
748+
this._cancelLongPressDelayTimeout(false);
744749
}
745750

746751
if (!IsActive[curState] && IsActive[nextState]) {
@@ -771,7 +776,9 @@ const TouchableMixin = {
771776
this._startHighlight(e);
772777
this._endHighlight(e);
773778
}
774-
this.touchableHandlePress(e);
779+
if (!this.preventOnPressTrigger) {
780+
this.touchableHandlePress(e);
781+
}
775782
}
776783
}
777784

0 commit comments

Comments
 (0)