From d69e60bb7a5cc8fe4daf488bd341790548f83236 Mon Sep 17 00:00:00 2001 From: Valentin Shergin Date: Tue, 18 Jul 2017 14:33:41 -0700 Subject: [PATCH] TextInput: Unified support of `clearTextOnFocus` prop Summary: The implementation of `clearTextOnFocus` was unified and moved to baseclass. Reviewed By: javache Differential Revision: D5299489 fbshipit-source-id: ff166f9bb0673ff8766f20b677f56810f64d7b2d --- Libraries/Text/RCTTextField.m | 9 --------- Libraries/Text/RCTTextFieldManager.m | 12 ++++++------ Libraries/Text/RCTTextInput.h | 2 ++ Libraries/Text/RCTTextInput.m | 13 +++++++++++++ Libraries/Text/RCTTextView.h | 1 - Libraries/Text/RCTTextView.m | 13 ------------- Libraries/Text/RCTTextViewManager.m | 13 +++++++------ 7 files changed, 28 insertions(+), 35 deletions(-) diff --git a/Libraries/Text/RCTTextField.m b/Libraries/Text/RCTTextField.m index e64174c9c..6470334be 100644 --- a/Libraries/Text/RCTTextField.m +++ b/Libraries/Text/RCTTextField.m @@ -162,15 +162,6 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithCoder:(NSCoder *)aDecoder) [self sendSelectionEvent]; } -- (void)textInputDidBeginEditing -{ - [_eventDispatcher sendTextEventWithType:RCTTextEventTypeFocus - reactTag:self.reactTag - text:_backedTextInput.text - key:nil - eventCount:_nativeEventCount]; -} - - (BOOL)textInputShouldEndEditing { _finalText = _backedTextInput.text; diff --git a/Libraries/Text/RCTTextFieldManager.m b/Libraries/Text/RCTTextFieldManager.m index 317a0868b..f43e60765 100644 --- a/Libraries/Text/RCTTextFieldManager.m +++ b/Libraries/Text/RCTTextFieldManager.m @@ -49,17 +49,17 @@ RCT_REMAP_VIEW_PROPERTY(secureTextEntry, backedTextInputView.secureTextEntry, BO RCT_REMAP_VIEW_PROPERTY(selectionColor, backedTextInputView.tintColor, UIColor) RCT_REMAP_VIEW_PROPERTY(spellCheck, backedTextInputView.spellCheckingType, UITextSpellCheckingType) RCT_REMAP_VIEW_PROPERTY(textAlign, backedTextInputView.textAlignment, NSTextAlignment) +RCT_EXPORT_VIEW_PROPERTY(blurOnSubmit, BOOL) +RCT_EXPORT_VIEW_PROPERTY(clearTextOnFocus, BOOL) +RCT_EXPORT_VIEW_PROPERTY(maxLength, NSNumber) +RCT_EXPORT_VIEW_PROPERTY(selectTextOnFocus, BOOL) +RCT_EXPORT_VIEW_PROPERTY(selection, RCTTextSelection) +RCT_EXPORT_VIEW_PROPERTY(text, NSString) #pragma mark - Singleline (aka TextField) specific properties RCT_REMAP_VIEW_PROPERTY(caretHidden, backedTextInputView.caretHidden, BOOL) -RCT_EXPORT_VIEW_PROPERTY(selection, RCTTextSelection) -RCT_EXPORT_VIEW_PROPERTY(text, NSString) -RCT_EXPORT_VIEW_PROPERTY(maxLength, NSNumber) RCT_REMAP_VIEW_PROPERTY(clearButtonMode, backedTextInputView.clearButtonMode, UITextFieldViewMode) -RCT_REMAP_VIEW_PROPERTY(clearTextOnFocus, backedTextInputView.clearsOnBeginEditing, BOOL) -RCT_EXPORT_VIEW_PROPERTY(selectTextOnFocus, BOOL) -RCT_EXPORT_VIEW_PROPERTY(blurOnSubmit, BOOL) RCT_EXPORT_VIEW_PROPERTY(onSelectionChange, RCTDirectEventBlock) RCT_CUSTOM_VIEW_PROPERTY(fontSize, NSNumber, RCTTextField) { diff --git a/Libraries/Text/RCTTextInput.h b/Libraries/Text/RCTTextInput.h index 8e789ae8a..294fb56b8 100644 --- a/Libraries/Text/RCTTextInput.h +++ b/Libraries/Text/RCTTextInput.h @@ -43,12 +43,14 @@ @property (nonatomic, assign) NSInteger mostRecentEventCount; @property (nonatomic, assign) BOOL blurOnSubmit; @property (nonatomic, assign) BOOL selectTextOnFocus; +@property (nonatomic, assign) BOOL clearTextOnFocus; - (void)invalidateContentSize; // Temporary exposure of particial `RCTBackedTextInputDelegate` support. // In the future all methods of the protocol should move to this class. - (BOOL)textInputShouldBeginEditing; +- (void)textInputDidBeginEditing; - (BOOL)textInputShouldReturn; - (void)textInputDidReturn; diff --git a/Libraries/Text/RCTTextInput.m b/Libraries/Text/RCTTextInput.m index 2640aab2b..7ba1435a0 100644 --- a/Libraries/Text/RCTTextInput.m +++ b/Libraries/Text/RCTTextInput.m @@ -97,6 +97,19 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithFrame:(CGRect)frame) return YES; } +- (void)textInputDidBeginEditing +{ + if (_clearTextOnFocus) { + self.backedTextInputView.text = @""; + } + + [_eventDispatcher sendTextEventWithType:RCTTextEventTypeFocus + reactTag:self.reactTag + text:self.backedTextInputView.text + key:nil + eventCount:_nativeEventCount]; +} + - (BOOL)textInputShouldReturn { return _blurOnSubmit; diff --git a/Libraries/Text/RCTTextView.h b/Libraries/Text/RCTTextView.h index ad5383cbb..5c55e26e6 100644 --- a/Libraries/Text/RCTTextView.h +++ b/Libraries/Text/RCTTextView.h @@ -20,7 +20,6 @@ @property (nonatomic, assign) UITextAutocorrectionType autocorrectionType; @property (nonatomic, assign) UITextSpellCheckingType spellCheckingType; -@property (nonatomic, assign) BOOL clearTextOnFocus; @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 7716e5c79..8b4a63574 100644 --- a/Libraries/Text/RCTTextView.m +++ b/Libraries/Text/RCTTextView.m @@ -329,19 +329,6 @@ static NSAttributedString *removeReactTagFromString(NSAttributedString *string) } } -- (void)textInputDidBeginEditing -{ - if (_clearTextOnFocus) { - _backedTextInput.text = @""; - } - - [_eventDispatcher sendTextEventWithType:RCTTextEventTypeFocus - reactTag:self.reactTag - text:nil - key:nil - eventCount:_nativeEventCount]; -} - static BOOL findMismatch(NSString *first, NSString *second, NSRange *firstRange, NSRange *secondRange) { NSInteger firstMismatch = -1; diff --git a/Libraries/Text/RCTTextViewManager.m b/Libraries/Text/RCTTextViewManager.m index 102842024..5f0fa6de9 100644 --- a/Libraries/Text/RCTTextViewManager.m +++ b/Libraries/Text/RCTTextViewManager.m @@ -49,20 +49,21 @@ RCT_REMAP_VIEW_PROPERTY(secureTextEntry, backedTextInputView.secureTextEntry, BO RCT_REMAP_VIEW_PROPERTY(selectionColor, backedTextInputView.tintColor, UIColor) RCT_REMAP_VIEW_PROPERTY(spellCheck, backedTextInputView.spellCheckingType, UITextSpellCheckingType) RCT_REMAP_VIEW_PROPERTY(textAlign, backedTextInputView.textAlignment, NSTextAlignment) - -#pragma mark - Multiline (aka TextView) specific properties - RCT_EXPORT_VIEW_PROPERTY(blurOnSubmit, BOOL) RCT_EXPORT_VIEW_PROPERTY(clearTextOnFocus, BOOL) RCT_EXPORT_VIEW_PROPERTY(maxLength, NSNumber) +RCT_EXPORT_VIEW_PROPERTY(selectTextOnFocus, BOOL) +RCT_EXPORT_VIEW_PROPERTY(selection, RCTTextSelection) +RCT_EXPORT_VIEW_PROPERTY(text, NSString) + +#pragma mark - Multiline (aka TextView) specific properties + RCT_EXPORT_VIEW_PROPERTY(onChange, RCTBubblingEventBlock) RCT_EXPORT_VIEW_PROPERTY(onContentSizeChange, RCTBubblingEventBlock) RCT_EXPORT_VIEW_PROPERTY(onSelectionChange, RCTDirectEventBlock) RCT_EXPORT_VIEW_PROPERTY(onScroll, RCTDirectEventBlock) RCT_EXPORT_VIEW_PROPERTY(onTextInput, RCTDirectEventBlock) -RCT_EXPORT_VIEW_PROPERTY(selectTextOnFocus, BOOL) -RCT_EXPORT_VIEW_PROPERTY(selection, RCTTextSelection) -RCT_EXPORT_VIEW_PROPERTY(text, NSString) + RCT_CUSTOM_VIEW_PROPERTY(fontSize, NSNumber, RCTTextView) { view.font = [RCTFont updateFont:view.font withSize:json ?: @(defaultView.font.pointSize)];