From 70426577c6cc873615562c1a9beb34bad427b514 Mon Sep 17 00:00:00 2001 From: Russell McClellan Date: Thu, 11 Apr 2019 00:21:28 -0400 Subject: [PATCH 1/2] Fix for bug where mouse coordinates are wrong This occurs when our main react view is not the contentView of a window. Touch coordinates are in window coordinates, but `hitTest` expects coordinates in the coordinate system of our superview. This is my first PR, let me know what I can do to get this in. --- React/Base/RCTTouchHandler.m | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/React/Base/RCTTouchHandler.m b/React/Base/RCTTouchHandler.m index 412eda07b1..e2c715d26d 100644 --- a/React/Base/RCTTouchHandler.m +++ b/React/Base/RCTTouchHandler.m @@ -106,10 +106,13 @@ - (void)_recordNewTouches:(NSSet *)touches NSPoint touchLocation = [touch locationInWindow]; - // adjust touchLocation if our view placed inside custom PopoverWindow if ([[self.view window].className isEqualToString:@"_NSPopoverWindow"]) { + // adjust touchLocation if our view placed inside custom PopoverWindow NSPoint rootOrigin = [self.view window].contentView.frame.origin; touchLocation = NSMakePoint(touchLocation.x - rootOrigin.x, touchLocation.y - rootOrigin.y); + } else if (self.view.superview) { + // if our view has a superview, adjust the window coordinates to view coordinates. + touchLocation = [touch.window.contentView convertPoint:touchLocation toView:self.view.superview]; } // TODO: get rid of explicit comparison From 1872ce83c3294909013ee05a46a048cfba3ce6b7 Mon Sep 17 00:00:00 2001 From: Russell McClellan Date: Sun, 14 Apr 2019 12:03:07 -0400 Subject: [PATCH 2/2] Crawl the NSView hierarchy to find a react-managed view This mirrors the behavior of upstream `react-native` for ios. --- React/Base/RCTTouchHandler.m | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/React/Base/RCTTouchHandler.m b/React/Base/RCTTouchHandler.m index e2c715d26d..9d96d756bc 100644 --- a/React/Base/RCTTouchHandler.m +++ b/React/Base/RCTTouchHandler.m @@ -115,17 +115,14 @@ - (void)_recordNewTouches:(NSSet *)touches touchLocation = [touch.window.contentView convertPoint:touchLocation toView:self.view.superview]; } - // TODO: get rid of explicit comparison - // - // Check if item is becoming first responder to delete touch NSView *targetView = [self.view hitTest:touchLocation]; - if (![targetView.className isEqualToString:@"RCTView"] && - ![targetView.className isEqualToString:@"RCTTextView"] && - ![targetView.className isEqualToString:@"RCTImageView"] && - ![targetView.className isEqualToString:@"ARTSurfaceView"]) { - self.state = NSGestureRecognizerStateEnded; - return; + // Find closest React-managed touchable view + while (targetView) { + if (targetView.reactTag) { + break; + } + targetView = targetView.superview; } NSNumber *reactTag = [self.view reactTagAtPoint:CGPointMake(touchLocation.x, touchLocation.y)];