diff --git a/Libraries/Text/TextInput/Multiline/RCTUITextView.m b/Libraries/Text/TextInput/Multiline/RCTUITextView.m index 05e0dd54410983..30292e41e17496 100644 --- a/Libraries/Text/TextInput/Multiline/RCTUITextView.m +++ b/Libraries/Text/TextInput/Multiline/RCTUITextView.m @@ -212,8 +212,12 @@ - (BOOL)becomeFirstResponder - (BOOL)resignFirstResponder { - BOOL success = [super resignFirstResponder]; + if (self.selectable) { + self.selectedRange = NSMakeRange(NSNotFound, 0); + } + BOOL success = [super resignFirstResponder]; + if (success) { // Break undo coalescing when losing focus. [self breakUndoCoalescing]; @@ -436,13 +440,13 @@ - (void)selectAll:(id)sender { [super selectAll:sender]; -#if !TARGET_OS_OSX // TODO(macOS GH#774) For `selectTextOnFocus` prop, which isn't supported on macOS atm. +#if !TARGET_OS_OSX // TODO(macOS GH#774) // `selectAll:` does not work for UITextView when it's being called inside UITextView's delegate methods. dispatch_async(dispatch_get_main_queue(), ^{ UITextRange *selectionRange = [self textRangeFromPosition:self.beginningOfDocument toPosition:self.endOfDocument]; [self setSelectedTextRange:selectionRange notifyDelegate:NO]; }); -#endif +#endif // TODO(macOS GH#774) } #pragma mark - Layout diff --git a/Libraries/Text/TextInput/RCTBaseTextInputView.m b/Libraries/Text/TextInput/RCTBaseTextInputView.m index d0a62e70490b85..539f7e7460ac0f 100644 --- a/Libraries/Text/TextInput/RCTBaseTextInputView.m +++ b/Libraries/Text/TextInput/RCTBaseTextInputView.m @@ -379,7 +379,13 @@ - (void)textInputDidBeginEditing } if (_selectTextOnFocus) { - [self.backedTextInputView selectAll:nil]; + if ([self.backedTextInputView respondsToSelector:@selector(selectAll:)]) { + [self.backedTextInputView selectAll:nil]; + } +#if TARGET_OS_OSX // [TODO(macOS GH#774) + } else { + [self.backedTextInputView setSelectedTextRange:NSMakeRange(NSNotFound, 0) notifyDelegate:NO]; +#endif // ]TODO(macOS GH#774) } [_eventDispatcher sendTextEventWithType:RCTTextEventTypeFocus diff --git a/Libraries/Text/TextInput/RCTBaseTextInputViewManager.m b/Libraries/Text/TextInput/RCTBaseTextInputViewManager.m index 47034882ee9640..d1de3945f8fab7 100644 --- a/Libraries/Text/TextInput/RCTBaseTextInputViewManager.m +++ b/Libraries/Text/TextInput/RCTBaseTextInputViewManager.m @@ -56,11 +56,11 @@ @implementation RCTBaseTextInputViewManager RCT_REMAP_NOT_OSX_VIEW_PROPERTY(secureTextEntry, backedTextInputView.secureTextEntry, BOOL) // TODO(macOS GH#774) RCT_EXPORT_VIEW_PROPERTY(autoFocus, BOOL) RCT_EXPORT_VIEW_PROPERTY(blurOnSubmit, BOOL) -RCT_EXPORT_NOT_OSX_VIEW_PROPERTY(clearTextOnFocus, BOOL) // TODO(macOS GH#774) +RCT_EXPORT_VIEW_PROPERTY(clearTextOnFocus, BOOL) RCT_REMAP_NOT_OSX_VIEW_PROPERTY(keyboardType, backedTextInputView.keyboardType, UIKeyboardType) // TODO(macOS GH#774) RCT_EXPORT_NOT_OSX_VIEW_PROPERTY(showSoftInputOnFocus, BOOL) // TODO(macOS GH#774) RCT_EXPORT_VIEW_PROPERTY(maxLength, NSNumber) -RCT_EXPORT_NOT_OSX_VIEW_PROPERTY(selectTextOnFocus, BOOL) // TODO(macOS GH#774) +RCT_EXPORT_VIEW_PROPERTY(selectTextOnFocus, BOOL) RCT_EXPORT_VIEW_PROPERTY(selection, RCTTextSelection) RCT_EXPORT_VIEW_PROPERTY(inputAccessoryViewID, NSString) RCT_EXPORT_VIEW_PROPERTY(textContentType, NSString)