Skip to content

Commit

Permalink
Only apply isHighlighted native prop on iOS
Browse files Browse the repository at this point in the history
Summary:
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.

[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: cadfe0cd64de8d98a10e3f24b3ae17b9bada8b3a
  • Loading branch information
rozele authored and facebook-github-bot committed Jul 26, 2023
1 parent 3c6dbec commit e3866eb
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 e3866eb

Please sign in to comment.