From d433da1b2fe102e541becd7014dc8bd0be216a71 Mon Sep 17 00:00:00 2001 From: Adam Gleitman Date: Mon, 6 Nov 2023 22:01:16 -0800 Subject: [PATCH] Don't recreate identical NSTrackingAreas (#1972) Co-authored-by: Adam Gleitman --- packages/react-native/React/Views/RCTView.m | 23 +++++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/packages/react-native/React/Views/RCTView.m b/packages/react-native/React/Views/RCTView.m index a78ff67c30f6b7..69f933cf86a3a7 100644 --- a/packages/react-native/React/Views/RCTView.m +++ b/packages/react-native/React/Views/RCTView.m @@ -1491,16 +1491,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];