Skip to content

Commit

Permalink
Don't send events when clicking on scrollbars (#1281)
Browse files Browse the repository at this point in the history
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 <skyle@fb.com>
  • Loading branch information
christophpurrer and appden authored Jul 26, 2022
1 parent 6f2f11f commit d69fa5b
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions React/Base/RCTTouchHandler.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit d69fa5b

Please sign in to comment.