Skip to content

Commit 8d07d9c

Browse files
committed
style(fabric, textinput): don't nil check the window before calling focus / blur
1 parent 225518c commit 8d07d9c

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

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

+5-8
Original file line numberDiff line numberDiff line change
@@ -531,10 +531,8 @@ - (void)focus
531531
#if !TARGET_OS_OSX // [macOS]
532532
[_backedTextInputView becomeFirstResponder];
533533
#else // [macOS
534-
NSWindow *window = _backedTextInputView.window;
535-
if (window) {
536-
[window makeFirstResponder:_backedTextInputView];
537-
}
534+
NSWindow *window = [_backedTextInputView window];
535+
[window makeFirstResponder:_backedTextInputView];
538536
#endif // macOS]
539537

540538
const auto &props = static_cast<const TextInputProps &>(*_props);
@@ -555,12 +553,11 @@ - (void)blur
555553
#if !TARGET_OS_OSX // [macOS]
556554
[_backedTextInputView resignFirstResponder];
557555
#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
556+
NSWindow *window = [_backedTextInputView window];
557+
if ([window firstResponder] == _backedTextInputView) {
561558
[window makeFirstResponder:nil];
562559
}
563-
#endif // macOS];
560+
#endif // macOS]
564561
}
565562

566563
- (void)setTextAndSelection:(NSInteger)eventCount

0 commit comments

Comments
 (0)