Skip to content

Commit ba0ccdf

Browse files
authored
MacOS mouse events show up at wrong locations (#260)
* macos mouse events showing up at wrong locations sometimes fix * cache some vars * minor var renames
1 parent d380cd8 commit ba0ccdf

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

Libraries/ActionSheetIOS/RCTActionSheetManager.m

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,15 +157,25 @@ - (void)presentViewController:(UIViewController *)alertController
157157
view = [self.bridge.uiManager viewForReactTag:anchorViewTag];
158158
event = [view.window currentEvent];
159159
}
160+
NSView *superview = [view superview];
160161
if (event && view) {
161-
origin = [view convertPoint:[event locationInWindow] fromView:nil];
162+
// On a macOS trackpad, soft taps are received as sysDefined event types. SysDefined event locations are relative to the screen so we have to convert those separately.
163+
NSPoint eventLocationRelativeToWindow = NSZeroPoint;
164+
CGPoint eventLocationInWindow = [event locationInWindow];
165+
if ([event type] == NSEventTypeSystemDefined) { // light tap event relative to screen
166+
eventLocationRelativeToWindow = [[view window] convertRectFromScreen:NSMakeRect(eventLocationInWindow.x, eventLocationInWindow.y, 0, 0)].origin;
167+
} else { // full click events are relative to the window
168+
eventLocationRelativeToWindow = eventLocationInWindow;
169+
}
170+
origin = [view convertPoint:eventLocationRelativeToWindow fromView:nil];
162171
} else if (view) {
163-
origin = NSMakePoint(NSMidX(view.superview.frame), NSMidY(view.superview.frame));
172+
CGRect superviewFrame = [superview frame];
173+
origin = NSMakePoint(NSMidX(superviewFrame), NSMidY(superviewFrame));
164174
} else {
165175
origin = [NSEvent mouseLocation];
166176
}
167177

168-
[menu popUpMenuPositioningItem:menu.itemArray.firstObject atLocation:origin inView:view.superview];
178+
[menu popUpMenuPositioningItem:menu.itemArray.firstObject atLocation:origin inView:superview];
169179
#endif // ]TODO(macOS ISS#2323203)
170180
}
171181

0 commit comments

Comments
 (0)