Add support for TextInput clearTextOnFocus and selectTextOnFocus (#1517)
* Enable `selectTextOnFocus` and `clearTextOnFocus` for TextInput * Fix select all for multiline textview * Only reset selected range for macOS * Don't run else branch for iOS * Fix tags Co-authored-by: Shawn Dempsey <shawndempsey@fb.com> Co-authored-by: chiuam <67026167+chiuam@users.noreply.github.com> Co-authored-by: Saad Najmi <sanajmi@microsoft.com>
This commit is contained in:
Родитель
b2c5fa9738
Коммит
71e7ccfc29
|
@ -212,8 +212,12 @@ static RCTUIColor *defaultPlaceholderColor() // TODO(OSS Candidate ISS#2710739)
|
|||
|
||||
- (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 @@ static RCTUIColor *defaultPlaceholderColor() // TODO(OSS Candidate ISS#2710739)
|
|||
{
|
||||
[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
|
||||
|
|
|
@ -379,7 +379,13 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithCoder:(NSCoder *)decoder)
|
|||
}
|
||||
|
||||
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
|
||||
|
|
|
@ -56,11 +56,11 @@ RCT_REMAP_NOT_OSX_VIEW_PROPERTY(clearButtonMode, backedTextInputView.clearButton
|
|||
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)
|
||||
|
|
Загрузка…
Ссылка в новой задаче