From 78467d279c018973ab9b130bfe8f7e44120bf815 Mon Sep 17 00:00:00 2001 From: Saad Najmi Date: Wed, 20 Nov 2024 10:06:55 -0800 Subject: [PATCH] style(fabric, textinput): don't nil check the window before calling focus / blur --- .../TextInput/RCTTextInputComponentView.mm | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/packages/react-native/React/Fabric/Mounting/ComponentViews/TextInput/RCTTextInputComponentView.mm b/packages/react-native/React/Fabric/Mounting/ComponentViews/TextInput/RCTTextInputComponentView.mm index 4aafb8c88cb954..83cfeb779dfc8e 100644 --- a/packages/react-native/React/Fabric/Mounting/ComponentViews/TextInput/RCTTextInputComponentView.mm +++ b/packages/react-native/React/Fabric/Mounting/ComponentViews/TextInput/RCTTextInputComponentView.mm @@ -531,10 +531,8 @@ - (void)focus #if !TARGET_OS_OSX // [macOS] [_backedTextInputView becomeFirstResponder]; #else // [macOS - NSWindow *window = _backedTextInputView.window; - if (window) { - [window makeFirstResponder:_backedTextInputView]; - } + NSWindow *window = [_backedTextInputView window]; + [window makeFirstResponder:_backedTextInputView]; #endif // macOS] const auto &props = static_cast(*_props); @@ -555,12 +553,11 @@ - (void)blur #if !TARGET_OS_OSX // [macOS] [_backedTextInputView resignFirstResponder]; #else // [macOS - NSWindow *window = _backedTextInputView.window; - if (window && window.firstResponder == _backedTextInputView) { - // Calling makeFirstResponder with nil will call resignFirstResponder and make the window the first responder + NSWindow *window = [_backedTextInputView window]; + if ([window firstResponder] == _backedTextInputView) { [window makeFirstResponder:nil]; } -#endif // macOS]; +#endif // macOS] } - (void)setTextAndSelection:(NSInteger)eventCount