Skip to content

Commit 0327eed

Browse files
Nick LefeverSaadnajmi
authored andcommitted
[fabric] Check for assigned event emitter before sending key/mouse events
Summary: This diff adds null checks to avoid sending key and/or mouse events before the event emitter was assigned to the component. Test Plan: * Run Zeratul with Fabric enabled * Hover over buttons * Use up/down arrows in composer on user tag selector https://pxl.cl/4jVCb Reviewers: shawndempsey, #rn-desktop Reviewed By: shawndempsey Differential Revision: https://phabricator.intern.facebook.com/D53555261
1 parent 2814ae2 commit 0327eed

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

packages/react-native/React/Fabric/Mounting/ComponentViews/View/RCTViewComponentView.mm

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1634,7 +1634,7 @@ - (BOOL)handleKeyboardEvent:(NSEvent *)event {
16341634
static const char kRCTViewKeyboardEventEmittedKey = 0;
16351635
NSNumber *emitted = objc_getAssociatedObject(event, &kRCTViewKeyboardEventEmittedKey);
16361636
BOOL alreadyEmitted = [emitted boolValue];
1637-
if (!alreadyEmitted) {
1637+
if (!alreadyEmitted && _eventEmitter) {
16381638
if (event.type == NSEventTypeKeyDown) {
16391639
_eventEmitter->onKeyDown(keyEvent);
16401640
} else {
@@ -1664,6 +1664,10 @@ - (void)keyUp:(NSEvent *)event {
16641664
#pragma mark - Mouse Events
16651665

16661666
- (void)sendMouseEvent:(BOOL)isMouseOver {
1667+
if (!_eventEmitter) {
1668+
return;
1669+
}
1670+
16671671
NSPoint locationInWindow = self.window.mouseLocationOutsideOfEventStream;
16681672
NSPoint locationInView = [self convertPoint:locationInWindow fromView:nil];
16691673

0 commit comments

Comments
 (0)