diff --git a/Libraries/Text/RCTTextField.h b/Libraries/Text/RCTTextField.h index 1c29fd91c..6e8d840b2 100644 --- a/Libraries/Text/RCTTextField.h +++ b/Libraries/Text/RCTTextField.h @@ -19,7 +19,6 @@ @interface RCTTextField : RCTTextInput @property (nonatomic, assign) BOOL caretHidden; -@property (nonatomic, assign) BOOL selectTextOnFocus; @property (nonatomic, strong) NSNumber *maxLength; @property (nonatomic, copy) RCTDirectEventBlock onSelectionChange; diff --git a/Libraries/Text/RCTTextField.m b/Libraries/Text/RCTTextField.m index 0f00e9eef..e64174c9c 100644 --- a/Libraries/Text/RCTTextField.m +++ b/Libraries/Text/RCTTextField.m @@ -162,11 +162,6 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithCoder:(NSCoder *)aDecoder) [self sendSelectionEvent]; } -- (BOOL)textInputShouldBeginEditing -{ - return YES; -} - - (void)textInputDidBeginEditing { [_eventDispatcher sendTextEventWithType:RCTTextEventTypeFocus @@ -174,14 +169,6 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithCoder:(NSCoder *)aDecoder) text:_backedTextInput.text key:nil eventCount:_nativeEventCount]; - - dispatch_async(dispatch_get_main_queue(), ^{ - if (self->_selectTextOnFocus) { - [self->_backedTextInput selectAll:nil]; - } - - [self sendSelectionEvent]; - }); } - (BOOL)textInputShouldEndEditing diff --git a/Libraries/Text/RCTTextInput.h b/Libraries/Text/RCTTextInput.h index efcd28403..8e789ae8a 100644 --- a/Libraries/Text/RCTTextInput.h +++ b/Libraries/Text/RCTTextInput.h @@ -42,11 +42,13 @@ @property (nonatomic, assign) NSInteger mostRecentEventCount; @property (nonatomic, assign) BOOL blurOnSubmit; +@property (nonatomic, assign) BOOL selectTextOnFocus; - (void)invalidateContentSize; // Temporary exposure of particial `RCTBackedTextInputDelegate` support. // In the future all methods of the protocol should move to this class. +- (BOOL)textInputShouldBeginEditing; - (BOOL)textInputShouldReturn; - (void)textInputDidReturn; diff --git a/Libraries/Text/RCTTextInput.m b/Libraries/Text/RCTTextInput.m index a5dc1f8a3..2640aab2b 100644 --- a/Libraries/Text/RCTTextInput.m +++ b/Libraries/Text/RCTTextInput.m @@ -86,6 +86,17 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithFrame:(CGRect)frame) #pragma mark - RCTBackedTextInputDelegate +- (BOOL)textInputShouldBeginEditing +{ + if (_selectTextOnFocus) { + dispatch_async(dispatch_get_main_queue(), ^{ + [self.backedTextInputView selectAll:nil]; + }); + } + + return YES; +} + - (BOOL)textInputShouldReturn { return _blurOnSubmit; diff --git a/Libraries/Text/RCTTextView.h b/Libraries/Text/RCTTextView.h index 2bd86c466..ad5383cbb 100644 --- a/Libraries/Text/RCTTextView.h +++ b/Libraries/Text/RCTTextView.h @@ -21,7 +21,6 @@ @property (nonatomic, assign) UITextAutocorrectionType autocorrectionType; @property (nonatomic, assign) UITextSpellCheckingType spellCheckingType; @property (nonatomic, assign) BOOL clearTextOnFocus; -@property (nonatomic, assign) BOOL selectTextOnFocus; @property (nonatomic, assign) BOOL automaticallyAdjustContentInsets; @property (nonatomic, copy) NSString *text; @property (nonatomic, strong) UIColor *placeholderTextColor; diff --git a/Libraries/Text/RCTTextView.m b/Libraries/Text/RCTTextView.m index 4d930d352..7716e5c79 100644 --- a/Libraries/Text/RCTTextView.m +++ b/Libraries/Text/RCTTextView.m @@ -329,16 +329,6 @@ static NSAttributedString *removeReactTagFromString(NSAttributedString *string) } } -- (BOOL)textInputShouldBeginEditing -{ - if (_selectTextOnFocus) { - dispatch_async(dispatch_get_main_queue(), ^{ - [self->_backedTextInput selectAll:nil]; - }); - } - return YES; -} - - (void)textInputDidBeginEditing { if (_clearTextOnFocus) { diff --git a/RNTester/js/TextInputExample.ios.js b/RNTester/js/TextInputExample.ios.js index 1e0c24e72..8c2b26534 100644 --- a/RNTester/js/TextInputExample.ios.js +++ b/RNTester/js/TextInputExample.ios.js @@ -684,6 +684,24 @@ exports.examples = [ selectTextOnFocus={true} /> + + + + + + ); }