From bff03634ac3bc92a2c7942e6b5fa491d2d293cd2 Mon Sep 17 00:00:00 2001 From: Adrien HARNAY Date: Thu, 6 May 2021 12:40:27 -0700 Subject: [PATCH] Add onPressIn & onPressOut props to Text (#31288) Summary: I added onPressIn & onPressOut props to Text to help implement custom highlighting logic (e.g. when clicking on a Text segment). Since TouchableOpacity can't be nested in Text having custom lineHeights without bugs in some occasions, this modification helps to replicate its behavior. ## Changelog [General] [Added] - Add onPressIn & onPressOut props to Text Pull Request resolved: https://github.com/facebook/react-native/pull/31288 Test Plan: ``` const [pressing, setPressing] = useState(false); setPressing(true)} onPressOut={() => setPressing(false)} style={{ opacity: pressing ? 0.5 : 1 }} /> ``` Thanks in advance! Reviewed By: yungsters Differential Revision: D27945133 Pulled By: appden fbshipit-source-id: 8342ca5f75986b4644a193d2f71eab3bc0ef1a5f --- Libraries/Text/Text.js | 6 ++++++ Libraries/Text/TextProps.js | 2 ++ 2 files changed, 8 insertions(+) diff --git a/Libraries/Text/Text.js b/Libraries/Text/Text.js index 1b334d3fda0..97ce10d0a20 100644 --- a/Libraries/Text/Text.js +++ b/Libraries/Text/Text.js @@ -34,6 +34,8 @@ const Text: React.AbstractComponent< ellipsizeMode, onLongPress, onPress, + onPressIn, + onPressOut, onResponderGrant, onResponderMove, onResponderRelease, @@ -64,9 +66,11 @@ const Text: React.AbstractComponent< onPress, onPressIn(event) { setHighlighted(!suppressHighlighting); + onPressIn?.(event); }, onPressOut(event) { setHighlighted(false); + onPressOut?.(event); }, onResponderTerminationRequest_DEPRECATED: onResponderTerminationRequest, onStartShouldSetResponder_DEPRECATED: onStartShouldSetResponder, @@ -78,6 +82,8 @@ const Text: React.AbstractComponent< pressRetentionOffset, onLongPress, onPress, + onPressIn, + onPressOut, onResponderTerminationRequest, onStartShouldSetResponder, suppressHighlighting, diff --git a/Libraries/Text/TextProps.js b/Libraries/Text/TextProps.js index 9555e576618..469f14522e3 100644 --- a/Libraries/Text/TextProps.js +++ b/Libraries/Text/TextProps.js @@ -122,6 +122,8 @@ export type TextProps = $ReadOnly<{| * See https://reactnative.dev/docs/text.html#onpress */ onPress?: ?(event: PressEvent) => mixed, + onPressIn?: ?(event: PressEvent) => mixed, + onPressOut?: ?(event: PressEvent) => mixed, onResponderGrant?: ?(event: PressEvent) => void, onResponderMove?: ?(event: PressEvent) => void, onResponderRelease?: ?(event: PressEvent) => void,