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);

<Text
  onPressIn={() => 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
This commit is contained in:
Adrien HARNAY 2021-05-06 12:40:27 -07:00 коммит произвёл Facebook GitHub Bot
Родитель 570c6f1f29
Коммит 1d924549ca
2 изменённых файлов: 8 добавлений и 0 удалений

Просмотреть файл

@ -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,

Просмотреть файл

@ -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,