Skip to content

Commit 8c5d0ec

Browse files
Fix cursor not showing when tabbing into multiline TextInput (#1342)
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 <[email protected]>
1 parent 2b31eb9 commit 8c5d0ec

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

Libraries/Text/TextInput/Multiline/RCTUITextView.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ - (NSAttributedString*)attributedText
172172

173173
- (BOOL)becomeFirstResponder
174174
{
175-
BOOL success = [[self window] makeFirstResponder:self];
175+
BOOL success = [super becomeFirstResponder];
176176

177177
if (success) {
178178
id<RCTBackedTextInputDelegate> textInputDelegate = [self textInputDelegate];

React/Views/UIView+React.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ - (void)reactFocus
286286
if (![[self window] makeFirstResponder:self]) {
287287
#else
288288
if (![self becomeFirstResponder]) {
289-
#endif //// TODO(macOS GH#774)]
289+
#endif // TODO(macOS GH#774)]
290290
self.reactIsFocusNeeded = YES;
291291
}
292292
}

0 commit comments

Comments
 (0)