Skip to content

Commit

Permalink
Don't recreate identical NSTrackingAreas (#1971)
Browse files Browse the repository at this point in the history
Co-authored-by: Adam Gleitman <adgleitm@microsoft.com>
  • Loading branch information
amgleitman and Adam Gleitman committed Nov 7, 2023
1 parent 178ff3a commit 65fb4c0
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions packages/react-native/React/Views/RCTView.m
Original file line number Diff line number Diff line change
Expand Up @@ -1492,16 +1492,21 @@ - (BOOL)acceptsFirstResponder

- (void)updateTrackingAreas
{
if (_trackingArea) {
[self removeTrackingArea:_trackingArea];
}
BOOL hasMouseHoverEvent = self.onMouseEnter || self.onMouseLeave;
BOOL wouldRecreateIdenticalTrackingArea = hasMouseHoverEvent && _trackingArea && NSEqualRects(self.bounds, [_trackingArea rect]);

if (!wouldRecreateIdenticalTrackingArea) {
if (_trackingArea) {
[self removeTrackingArea:_trackingArea];
}

if (self.onMouseEnter || self.onMouseLeave) {
_trackingArea = [[NSTrackingArea alloc] initWithRect:self.bounds
options:NSTrackingActiveAlways|NSTrackingMouseEnteredAndExited
owner:self
userInfo:nil];
[self addTrackingArea:_trackingArea];
if (hasMouseHoverEvent) {
_trackingArea = [[NSTrackingArea alloc] initWithRect:self.bounds
options:NSTrackingActiveAlways|NSTrackingMouseEnteredAndExited
owner:self
userInfo:nil];
[self addTrackingArea:_trackingArea];
}
}

[super updateTrackingAreas];
Expand Down

0 comments on commit 65fb4c0

Please sign in to comment.