Skip to content

Commit 43c7dfb

Browse files
amgleitmanAdam Gleitman
andauthored
Don't recreate identical NSTrackingAreas (#1973)
Co-authored-by: Adam Gleitman <adgleitm@microsoft.com>
1 parent 34b8bc0 commit 43c7dfb

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

packages/react-native/React/Views/RCTView.m

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1492,16 +1492,21 @@ - (BOOL)acceptsFirstResponder
14921492

14931493
- (void)updateTrackingAreas
14941494
{
1495-
if (_trackingArea) {
1496-
[self removeTrackingArea:_trackingArea];
1497-
}
1495+
BOOL hasMouseHoverEvent = self.onMouseEnter || self.onMouseLeave;
1496+
BOOL wouldRecreateIdenticalTrackingArea = hasMouseHoverEvent && _trackingArea && NSEqualRects(self.bounds, [_trackingArea rect]);
1497+
1498+
if (!wouldRecreateIdenticalTrackingArea) {
1499+
if (_trackingArea) {
1500+
[self removeTrackingArea:_trackingArea];
1501+
}
14981502

1499-
if (self.onMouseEnter || self.onMouseLeave) {
1500-
_trackingArea = [[NSTrackingArea alloc] initWithRect:self.bounds
1501-
options:NSTrackingActiveAlways|NSTrackingMouseEnteredAndExited
1502-
owner:self
1503-
userInfo:nil];
1504-
[self addTrackingArea:_trackingArea];
1503+
if (hasMouseHoverEvent) {
1504+
_trackingArea = [[NSTrackingArea alloc] initWithRect:self.bounds
1505+
options:NSTrackingActiveAlways|NSTrackingMouseEnteredAndExited
1506+
owner:self
1507+
userInfo:nil];
1508+
[self addTrackingArea:_trackingArea];
1509+
}
15051510
}
15061511

15071512
[super updateTrackingAreas];

0 commit comments

Comments
 (0)