From 3d2fd4bf228c64b1f46dc4737cf5c8eb50392eb0 Mon Sep 17 00:00:00 2001 From: Eric Rozell Date: Wed, 26 Jul 2023 12:45:41 -0700 Subject: [PATCH] Only apply isHighlighted native prop on iOS (#38642) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/38642 isHighlighted is only used for iOS. Even macOS disables it (see https://github.com/microsoft/react-native-macos/pull/1346). This change ensures that the isHighlighted prop is only updated for iOS. ## Changelog: [General] [Fixed] - Avoids re-renders during text selection on desktop platforms by limiting native-only `isHighlighted` prop to iOS Reviewed By: lenaic, sammy-SC Differential Revision: D47800845 fbshipit-source-id: af109be17027b2fbc9408e2ec9e1b841c709fe35 --- packages/react-native/Libraries/Text/Text.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/react-native/Libraries/Text/Text.js b/packages/react-native/Libraries/Text/Text.js index d473178deb5490..0736e987f266c3 100644 --- a/packages/react-native/Libraries/Text/Text.js +++ b/packages/react-native/Libraries/Text/Text.js @@ -105,7 +105,13 @@ const Text: React.AbstractComponent< onLongPress, onPress, onPressIn(event: PressEvent) { - setHighlighted(!suppressHighlighting); + // Updating isHighlighted causes unnecessary re-renders for platforms that don't use it + // in the best case, and cause issues with text selection in the worst case. Forcing + // the isHighlighted prop to false on all platforms except iOS. + setHighlighted( + (suppressHighlighting == null || !suppressHighlighting) && + Platform.OS === 'ios', + ); onPressIn?.(event); }, onPressOut(event: PressEvent) {