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
This commit is contained in:
Родитель
f8bc32abb0
Коммит
3bef4bddbf
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче