Skip to content

Commit 48950aa

Browse files
Nick LefeverSaadnajmi
authored andcommitted
[fabric] Make text input first responder through the window instance
Summary: Fix AppKit exception throws when focusing text inputs by calling becomeFirstResponder directly on the backing text input view. Making a view first responder has to happen through the window using makeFirstResponder. 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 - The composer gets focus without AppKit throwing an exception. https://pxl.cl/3dVMx Reviewers: shawndempsey, #rn-desktop Reviewed By: shawndempsey Differential Revision: https://phabricator.intern.facebook.com/D48696690
1 parent c952214 commit 48950aa

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,14 @@ - (void)handleCommand:(const NSString *)commandName args:(const NSArray *)args
528528

529529
- (void)focus
530530
{
531+
#if !TARGET_OS_OSX // [macOS]
531532
[_backedTextInputView becomeFirstResponder];
533+
#else // [macOS
534+
NSWindow *window = _backedTextInputView.window;
535+
if (window) {
536+
[window makeFirstResponder:_backedTextInputView];
537+
}
538+
#endif // macOS]
532539

533540
const auto &props = static_cast<const TextInputProps &>(*_props);
534541

0 commit comments

Comments
 (0)