Skip to content

Commit

Permalink
Only apply isHighlighted native prop on iOS (facebook#38642)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: facebook#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: 9888db039f5b955da0c3dfa43dd304f3f4d01f19
  • Loading branch information
rozele authored and facebook-github-bot committed Jul 26, 2023
1 parent 6cd1da9 commit 6afd4c5
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 6afd4c5

Please sign in to comment.