From cb96f1d5d2d1eb66daf004a2b48beaf94cbd44cf Mon Sep 17 00:00:00 2001 From: Valentin Shergin Date: Tue, 18 Jul 2017 14:33:37 -0700 Subject: [PATCH] TextInput: Unified support of `clearsOnBeginEditing` prop Summary: The implementation of `clearsOnBeginEditing` was unified and moved to superclass. Reviewed By: javache Differential Revision: D5299396 fbshipit-source-id: 98c5494a782cbe4df5b2d6021828eb7b2012f6dc --- Libraries/Text/RCTTextField.h | 1 - Libraries/Text/RCTTextField.m | 13 ------------- Libraries/Text/RCTTextInput.h | 2 ++ Libraries/Text/RCTTextInput.m | 11 +++++++++++ Libraries/Text/RCTTextView.h | 1 - Libraries/Text/RCTTextView.m | 10 ---------- RNTester/js/TextInputExample.ios.js | 18 ++++++++++++++++++ 7 files changed, 31 insertions(+), 25 deletions(-) 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} /> + + + + + + ); }