From fac05036a363567f5b88b3c5d5ace862d9f25e1a 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 --- Libraries/Text/Text.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Libraries/Text/Text.js b/Libraries/Text/Text.js index dde3a5b4d75d45..e4d89a9e589d41 100644 --- a/Libraries/Text/Text.js +++ b/Libraries/Text/Text.js @@ -108,7 +108,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) {