Skip to content

Commit

Permalink
Only apply isHighlighted native prop on iOS (#38642)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
rozele authored and facebook-github-bot committed Jul 26, 2023
1 parent 6cd1da9 commit 3d2fd4b
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion packages/react-native/Libraries/Text/Text.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 3d2fd4b

Please sign in to comment.