From 6afd4c58399d73fe3c16fcce763feafa83927c2e Mon Sep 17 00:00:00 2001 From: Eric Rozell Date: Wed, 26 Jul 2023 11:12:14 -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: 9888db039f5b955da0c3dfa43dd304f3f4d01f19 --- 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) {