Skip to content

Commit 3d2fd4b

Browse files
rozelefacebook-github-bot
authored andcommitted
Only apply isHighlighted native prop on iOS (#38642)
Summary: Pull Request resolved: #38642 isHighlighted is only used for iOS. Even macOS disables it (see microsoft#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
1 parent 6cd1da9 commit 3d2fd4b

File tree

1 file changed

+7
-1
lines changed
  • packages/react-native/Libraries/Text

1 file changed

+7
-1
lines changed

packages/react-native/Libraries/Text/Text.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,13 @@ const Text: React.AbstractComponent<
105105
onLongPress,
106106
onPress,
107107
onPressIn(event: PressEvent) {
108-
setHighlighted(!suppressHighlighting);
108+
// Updating isHighlighted causes unnecessary re-renders for platforms that don't use it
109+
// in the best case, and cause issues with text selection in the worst case. Forcing
110+
// the isHighlighted prop to false on all platforms except iOS.
111+
setHighlighted(
112+
(suppressHighlighting == null || !suppressHighlighting) &&
113+
Platform.OS === 'ios',
114+
);
109115
onPressIn?.(event);
110116
},
111117
onPressOut(event: PressEvent) {

0 commit comments

Comments
 (0)