Skip to content

Commit 225518c

Browse files
Nick LefeverSaadnajmi
authored andcommitted
[fabric] Make text input resign first responder through the window instance
Summary: Fix AppKit exception throws when blurring text inputs by calling `resignFirstResponder` directly on the backing text input view. Resigning the first responder state has to happen through the window by calling `[window makeFirstResponder:nil]` which will: - call `resignFirstResponder` on the current first responder - if successful, the window will become the first responder Test Plan: - Run Zeratul with Fabric - Focus the search text input above the message threads - Click inside the active message thread to trigger the auto-focus of the composer and the blur on the search field - The focused field resigns the first responder status without throwing an exception https://pxl.cl/3GvZD Reviewers: shawndempsey, #rn-desktop Reviewed By: shawndempsey Differential Revision: https://phabricator.intern.facebook.com/D50700782
1 parent 48950aa commit 225518c

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

packages/react-native/React/Fabric/Mounting/ComponentViews/TextInput/RCTTextInputComponentView.mm

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,15 @@ - (void)focus
552552

553553
- (void)blur
554554
{
555+
#if !TARGET_OS_OSX // [macOS]
555556
[_backedTextInputView resignFirstResponder];
557+
#else // [macOS
558+
NSWindow *window = _backedTextInputView.window;
559+
if (window && window.firstResponder == _backedTextInputView) {
560+
// Calling makeFirstResponder with nil will call resignFirstResponder and make the window the first responder
561+
[window makeFirstResponder:nil];
562+
}
563+
#endif // macOS];
556564
}
557565

558566
- (void)setTextAndSelection:(NSInteger)eventCount

0 commit comments

Comments
 (0)