Permalink
Browse files

show touchable feedback for short touches

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...
1 parent a140251 commit 891550724450988a440756170b2475f1da6f9ba2 @foghina foghina committed with Facebook Github Bot Oct 3, 2016
Showing with 26 additions and 11 deletions.
  1. +26 −11 Libraries/Components/Touchable/Touchable.js
@@ -690,16 +690,9 @@ var TouchableMixin = {
}
if (newIsHighlight && !curIsHighlight) {
- this._savePressInLocation(e);
- this.touchableHandleActivePressIn && this.touchableHandleActivePressIn(e);
- } else if (!newIsHighlight && curIsHighlight && this.touchableHandleActivePressOut) {
- if (this.touchableGetPressOutDelayMS && this.touchableGetPressOutDelayMS()) {
- this.pressOutDelayTimeout = setTimeout(() => {
- this.touchableHandleActivePressOut(e);
- }, this.touchableGetPressOutDelayMS());
- } else {
- this.touchableHandleActivePressOut(e);
- }
+ this._startHighlight(e);
+ } else if (!newIsHighlight && curIsHighlight) {
+ this._endHighlight(e);
}
if (IsPressingIn[curState] && signal === Signals.RESPONDER_RELEASE) {
@@ -712,13 +705,35 @@ var TouchableMixin = {
var shouldInvokePress = !IsLongPressingIn[curState] || pressIsLongButStillCallOnPress;
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.touchableDelayTimeout && clearTimeout(this.touchableDelayTimeout);
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);
+ }
+ }
+ },
};

0 comments on commit 8915507

Please sign in to comment.