Skip to content

Commit 3bef4bd

Browse files
rickhanloniifacebook-github-bot
authored andcommitted
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
1 parent f8bc32a commit 3bef4bd

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

Libraries/Components/Touchable/Touchable.js

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -498,14 +498,6 @@ const TouchableMixin = {
498498
* Place as callback for a DOM element's `onResponderMove` event.
499499
*/
500500
touchableHandleResponderMove: function(e: PressEvent) {
501-
// Not enough time elapsed yet, wait for highlight -
502-
// this is just a perf optimization.
503-
if (
504-
this.state.touchable.touchState === States.RESPONDER_INACTIVE_PRESS_IN
505-
) {
506-
return;
507-
}
508-
509501
// Measurement may not have returned yet.
510502
if (!this.state.touchable.positionOnActivate) {
511503
return;
@@ -841,7 +833,12 @@ const TouchableMixin = {
841833
this._cancelLongPressDelayTimeout();
842834
}
843835

844-
if (!IsActive[curState] && IsActive[nextState]) {
836+
const isInitialTransition =
837+
curState === States.NOT_RESPONDER &&
838+
nextState === States.RESPONDER_INACTIVE_PRESS_IN;
839+
840+
const isActiveTransition = !IsActive[curState] && IsActive[nextState];
841+
if (isInitialTransition || isActiveTransition) {
845842
this._remeasureMetricsOnActivation();
846843
}
847844

0 commit comments

Comments
 (0)