Skip to content

Commit

Permalink
show touchable feedback for short touches
Browse files Browse the repository at this point in the history
Summary: Currently, for short touches (under 130ms by default), we don't trigger the highlight effect. This diff makes it so that if we're not highlighted when we invoke onPress, we highlight.

Reviewed By: astreet

Differential Revision: D3932019

fbshipit-source-id: c0ff7d4c646890507ce510f51c279c88aeba66ae
  • Loading branch information
foghina authored and Facebook Github Bot committed Oct 3, 2016
1 parent a140251 commit 8915507
Showing 1 changed file with 26 additions and 11 deletions.
37 changes: 26 additions & 11 deletions Libraries/Components/Touchable/Touchable.js
Expand Up @@ -690,16 +690,9 @@ var TouchableMixin = {
} }


if (newIsHighlight && !curIsHighlight) { if (newIsHighlight && !curIsHighlight) {
this._savePressInLocation(e); this._startHighlight(e);
this.touchableHandleActivePressIn && this.touchableHandleActivePressIn(e); } else if (!newIsHighlight && curIsHighlight) {
} else if (!newIsHighlight && curIsHighlight && this.touchableHandleActivePressOut) { this._endHighlight(e);
if (this.touchableGetPressOutDelayMS && this.touchableGetPressOutDelayMS()) {
this.pressOutDelayTimeout = setTimeout(() => {
this.touchableHandleActivePressOut(e);
}, this.touchableGetPressOutDelayMS());
} else {
this.touchableHandleActivePressOut(e);
}
} }


if (IsPressingIn[curState] && signal === Signals.RESPONDER_RELEASE) { if (IsPressingIn[curState] && signal === Signals.RESPONDER_RELEASE) {
Expand All @@ -712,13 +705,35 @@ var TouchableMixin = {


var shouldInvokePress = !IsLongPressingIn[curState] || pressIsLongButStillCallOnPress; var shouldInvokePress = !IsLongPressingIn[curState] || pressIsLongButStillCallOnPress;
if (shouldInvokePress && this.touchableHandlePress) { if (shouldInvokePress && this.touchableHandlePress) {
if (!newIsHighlight && !curIsHighlight) {
// we never highlighted because of delay, but we should highlight now
this._startHighlight(e);
this._endHighlight(e);
}
this.touchableHandlePress(e); this.touchableHandlePress(e);
} }
} }


this.touchableDelayTimeout && clearTimeout(this.touchableDelayTimeout); this.touchableDelayTimeout && clearTimeout(this.touchableDelayTimeout);
this.touchableDelayTimeout = null; this.touchableDelayTimeout = null;
} },

_startHighlight: function(e) {
this._savePressInLocation(e);
this.touchableHandleActivePressIn && this.touchableHandleActivePressIn(e);
},

_endHighlight: function(e) {
if (this.touchableHandleActivePressOut) {
if (this.touchableGetPressOutDelayMS && this.touchableGetPressOutDelayMS()) {
this.pressOutDelayTimeout = setTimeout(() => {
this.touchableHandleActivePressOut(e);
}, this.touchableGetPressOutDelayMS());
} else {
this.touchableHandleActivePressOut(e);
}
}
},


}; };


Expand Down

0 comments on commit 8915507

Please sign in to comment.