Skip to content

Commit

Permalink
Measure responder region on first state transition
Browse files Browse the repository at this point in the history
Summary:
This diff fixes a bug in Touchable and Pressability where a long delay setting would unwillingly trigger presses by the user.

The cause of this bug is that we were not calculating the responder region until _after_ the delay. If you were to lift up outside of the press rect _before_ we calculate the responder region, we wouldn't be able to calculate that you're outside of the region (i.e. never transitioned to an "out" state) and would register the press

The fix is to start the calculation as soon as you transition into the initial state, so the calculation is available by the time we need to check if you're in an out state

Reviewed By: TheSavior

Differential Revision: D13412934

fbshipit-source-id: 55d1c2a9e70d4e3ce268f92075d7d09dd842a81e
  • Loading branch information
rickhanlonii authored and facebook-github-bot committed Dec 12, 2018
1 parent f8bc32a commit 3bef4bd
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions Libraries/Components/Touchable/Touchable.js
Original file line number Diff line number Diff line change
Expand Up @@ -498,14 +498,6 @@ const TouchableMixin = {
* Place as callback for a DOM element's `onResponderMove` event.
*/
touchableHandleResponderMove: function(e: PressEvent) {
// Not enough time elapsed yet, wait for highlight -
// this is just a perf optimization.
if (
this.state.touchable.touchState === States.RESPONDER_INACTIVE_PRESS_IN
) {
return;
}

// Measurement may not have returned yet.
if (!this.state.touchable.positionOnActivate) {
return;
Expand Down Expand Up @@ -841,7 +833,12 @@ const TouchableMixin = {
this._cancelLongPressDelayTimeout();
}

if (!IsActive[curState] && IsActive[nextState]) {
const isInitialTransition =
curState === States.NOT_RESPONDER &&
nextState === States.RESPONDER_INACTIVE_PRESS_IN;

const isActiveTransition = !IsActive[curState] && IsActive[nextState];
if (isInitialTransition || isActiveTransition) {
this._remeasureMetricsOnActivation();
}

Expand Down

0 comments on commit 3bef4bd

Please sign in to comment.