Skip to content

Commit f3bf2e4

Browse files
rozelefacebook-github-bot
authored andcommitted
Add isPressable native prop to Text
Summary: react-native-windows currently needs to maintain a fork of TextNativeComponent to wire through a native-only prop for `isPressable`. The reason we do this on Windows is that we implement an optimization so we only attempt to hit test a virtual Text node if it is actually pressable, leading to significant perf improvement for pointer events (e.g., onMouseEnter / onMouseLeave) on Text. Changelog: [General][Added] - Native-only prop to optimize text hit testing on some RN platforms Reviewed By: JoshuaGross Differential Revision: D32564637 fbshipit-source-id: bf47c68d94a930d2c620cb3b1584355c5e412bd4
1 parent 363ff5c commit f3bf2e4

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

Libraries/Text/Text.js

+1
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ const Text: React.AbstractComponent<
163163
{...restProps}
164164
{...eventHandlersForText}
165165
isHighlighted={isHighlighted}
166+
isPressable={isPressable}
166167
numberOfLines={numberOfLines}
167168
selectionColor={selectionColor}
168169
style={style}

Libraries/Text/TextNativeComponent.js

+6
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,18 @@ type NativeTextProps = $ReadOnly<{
1919
...TextProps,
2020
isHighlighted?: ?boolean,
2121
selectionColor?: ?ProcessedColorValue,
22+
// This is only needed for platforms that optimize text hit testing, e.g.,
23+
// react-native-windows. It can be used to only hit test virtual text spans
24+
// that have pressable events attached to them.
25+
isPressable?: ?boolean,
2226
}>;
2327

2428
export const NativeText: HostComponent<NativeTextProps> =
2529
(createReactNativeComponentClass('RCTText', () => ({
2630
validAttributes: {
2731
...ReactNativeViewAttributes.UIView,
2832
isHighlighted: true,
33+
isPressable: true,
2934
numberOfLines: true,
3035
ellipsizeMode: true,
3136
allowFontScaling: true,
@@ -59,6 +64,7 @@ export const NativeVirtualText: HostComponent<NativeTextProps> =
5964
validAttributes: {
6065
...ReactNativeViewAttributes.UIView,
6166
isHighlighted: true,
67+
isPressable: true,
6268
maxFontSizeMultiplier: true,
6369
},
6470
uiViewClassName: 'RCTVirtualText',

0 commit comments

Comments
 (0)