From 3bef4bddbfbdaaa7f431bbada5d72c26e01a45d6 Mon Sep 17 00:00:00 2001 From: Rick Hanlon Date: Tue, 11 Dec 2018 22:34:33 -0800 Subject: [PATCH] Measure responder region on first state transition 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 --- Libraries/Components/Touchable/Touchable.js | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/Libraries/Components/Touchable/Touchable.js b/Libraries/Components/Touchable/Touchable.js index 99663191b4..65a82b1c4f 100644 --- a/Libraries/Components/Touchable/Touchable.js +++ b/Libraries/Components/Touchable/Touchable.js @@ -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; @@ -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(); }