From f3bf2e4f51897f1bb71e37002c288ebf3b23cf78 Mon Sep 17 00:00:00 2001 From: Eric Rozell Date: Tue, 30 Nov 2021 21:54:17 -0800 Subject: [PATCH] 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 --- Libraries/Text/Text.js | 1 + Libraries/Text/TextNativeComponent.js | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/Libraries/Text/Text.js b/Libraries/Text/Text.js index cd28d02a04dca1..54476ca5369a67 100644 --- a/Libraries/Text/Text.js +++ b/Libraries/Text/Text.js @@ -163,6 +163,7 @@ const Text: React.AbstractComponent< {...restProps} {...eventHandlersForText} isHighlighted={isHighlighted} + isPressable={isPressable} numberOfLines={numberOfLines} selectionColor={selectionColor} style={style} diff --git a/Libraries/Text/TextNativeComponent.js b/Libraries/Text/TextNativeComponent.js index da238a1222a5df..615b9d264d496e 100644 --- a/Libraries/Text/TextNativeComponent.js +++ b/Libraries/Text/TextNativeComponent.js @@ -19,6 +19,10 @@ type NativeTextProps = $ReadOnly<{ ...TextProps, isHighlighted?: ?boolean, selectionColor?: ?ProcessedColorValue, + // This is only needed for platforms that optimize text hit testing, e.g., + // react-native-windows. It can be used to only hit test virtual text spans + // that have pressable events attached to them. + isPressable?: ?boolean, }>; export const NativeText: HostComponent = @@ -26,6 +30,7 @@ export const NativeText: HostComponent = validAttributes: { ...ReactNativeViewAttributes.UIView, isHighlighted: true, + isPressable: true, numberOfLines: true, ellipsizeMode: true, allowFontScaling: true, @@ -59,6 +64,7 @@ export const NativeVirtualText: HostComponent = validAttributes: { ...ReactNativeViewAttributes.UIView, isHighlighted: true, + isPressable: true, maxFontSizeMultiplier: true, }, uiViewClassName: 'RCTVirtualText',