From bdf3c7911007f547101d753903da11ea4ee095f9 Mon Sep 17 00:00:00 2001 From: Tim Yung Date: Fri, 11 Sep 2020 19:04:02 -0700 Subject: [PATCH] RN: Fix TouchableHighlight w/o `onLongPress` Summary: When `TouchableHighlight` was migrated to use `Pressability`, a bug was introduced due to `onLongPress` being unconditionally supplied as a callback. This bug leads to `onPress` not firing if the element is pressed for longer than 500ms, even when `onLongPress` is not supplied. Closes #29040. Changelog: [General][Fixed] - TouchableHighlight fires `onPress` when pressed for >500ms, when `onLongPress` is not supplied. Reviewed By: TheSavior Differential Revision: D23664365 fbshipit-source-id: 3a0e92e276871eedd303888346a13433be15ac47 --- Libraries/Components/Touchable/TouchableBounce.js | 6 +----- Libraries/Components/Touchable/TouchableHighlight.js | 6 +----- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/Libraries/Components/Touchable/TouchableBounce.js b/Libraries/Components/Touchable/TouchableBounce.js index 3a89c55d142..0403be409ec 100644 --- a/Libraries/Components/Touchable/TouchableBounce.js +++ b/Libraries/Components/Touchable/TouchableBounce.js @@ -72,11 +72,7 @@ class TouchableBounce extends React.Component { this.props.onFocus(event); } }, - onLongPress: event => { - if (this.props.onLongPress != null) { - this.props.onLongPress(event); - } - }, + onLongPress: this.props.onLongPress, onPress: event => { const {onPressAnimationComplete, onPressWithCompletion} = this.props; const releaseBounciness = this.props.releaseBounciness ?? 10; diff --git a/Libraries/Components/Touchable/TouchableHighlight.js b/Libraries/Components/Touchable/TouchableHighlight.js index 350ea535e11..9987ec7f704 100644 --- a/Libraries/Components/Touchable/TouchableHighlight.js +++ b/Libraries/Components/Touchable/TouchableHighlight.js @@ -193,11 +193,7 @@ class TouchableHighlight extends React.Component { this.props.onFocus(event); } }, - onLongPress: event => { - if (this.props.onLongPress != null) { - this.props.onLongPress(event); - } - }, + onLongPress: this.props.onLongPress, onPress: event => { if (this._hideTimeout != null) { clearTimeout(this._hideTimeout);