From d69fa5b435130fa484f4e1fdd542b18a49aec33e Mon Sep 17 00:00:00 2001 From: Christoph Purrer Date: Tue, 26 Jul 2022 10:16:32 -0700 Subject: [PATCH] Don't send events when clicking on scrollbars (#1281) This will ignore "touches" (clicks) on `NSScroller` such that JS does not process them resulting in a press event. Confirmed clicking scrollbar in rn-tester does not result in a click on the items underneath. Co-authored-by: Scott Kyle --- React/Base/RCTTouchHandler.m | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/React/Base/RCTTouchHandler.m b/React/Base/RCTTouchHandler.m index b8e4e28b49d9e9..e7a2cd5a1b3c0f 100644 --- a/React/Base/RCTTouchHandler.m +++ b/React/Base/RCTTouchHandler.m @@ -129,6 +129,10 @@ - (void)_recordNewTouches:(NSSet *)touches // The assumption here is that a RCTUIView/RCTSurfaceView will always have a superview. CGPoint touchLocation = [self.view.superview convertPoint:touch.locationInWindow fromView:nil]; NSView *targetView = [self.view hitTest:touchLocation]; + // Don't record clicks on scrollbars. + if ([targetView isKindOfClass:[NSScroller class]]) { + continue; + } // Pair the mouse down events with mouse up events so our _nativeTouches cache doesn't get stale if ([targetView isKindOfClass:[NSControl class]]) { _shouldSendMouseUpOnSystemBehalf = [(NSControl*)targetView isEnabled]; @@ -395,6 +399,11 @@ - (void)interactionsBegan:(NSSet *)touches // TODO(macOS GH#774) // "end"/"cancel" needs to remove the touch *after* extracting the event. [self _recordNewTouches:touches]; + // [TODO(macOS GH#774) - Filter out touches that were ignored. + touches = [touches objectsPassingTest:^(id touch, BOOL *stop) { + return [_nativeTouches containsObject:touch]; + }]; // ]TODO(macOS GH#774) + [self _updateAndDispatchTouches:touches eventName:@"touchStart"]; if (self.state == UIGestureRecognizerStatePossible) {