Skip to content

Commit

Permalink
Fix cursor not showing when tabbing into multiline TextInput (#1342)
Browse files Browse the repository at this point in the history
This bug happens because `RCTUITextView` (which multiline TextInput uses) was overriding NSTextView's `becomeFirstResponder` method and didn't call `[super becomeFirstResponder]`.
This seems to mess with AppKit's logic of drawing the cursor initially.

This is alluded to in the [docs](https://developer.apple.com/documentation/appkit/nstextview/1807130-becomefirstresponder?language=objc#) for `[NSTextView becomeFirstResponder]`:

> If the previous first responder was not a text view on the same layout manager as the receiving text view, this method draws the selection and updates the insertion point if necessary.

Simply switching to call `[super becomeFirstResponder]` led to a cryptic exception within AppKit. This was likely because in the `reactFocus` (and `reactFocusIfNeeded`) we were calling `becomeFirstResponder` directly.
The [docs](https://developer.apple.com/documentation/appkit/nsresponder/1526750-becomefirstresponder?language=objc#) for `[NSResponder becomeFirstResponder]` say:

> Use the NSWindow makeFirstResponder: method, not this method, to make an object the first responder. Never invoke this method directly.

This fixed the issue

Co-authored-by: Liron Yahdav <lyahdav@fb.com>
  • Loading branch information
christophpurrer and lyahdav authored Aug 9, 2022
1 parent 2b31eb9 commit 8c5d0ec
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Libraries/Text/TextInput/Multiline/RCTUITextView.m
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ - (NSAttributedString*)attributedText

- (BOOL)becomeFirstResponder
{
BOOL success = [[self window] makeFirstResponder:self];
BOOL success = [super becomeFirstResponder];

if (success) {
id<RCTBackedTextInputDelegate> textInputDelegate = [self textInputDelegate];
Expand Down
2 changes: 1 addition & 1 deletion React/Views/UIView+React.m
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ - (void)reactFocus
if (![[self window] makeFirstResponder:self]) {
#else
if (![self becomeFirstResponder]) {
#endif //// TODO(macOS GH#774)]
#endif // TODO(macOS GH#774)]
self.reactIsFocusNeeded = YES;
}
}
Expand Down

0 comments on commit 8c5d0ec

Please sign in to comment.