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
This commit is contained in:
Valentin Shergin 2017-07-18 14:33:37 -07:00 committed by Facebook Github Bot
parent 8f93ce680d
commit cb96f1d5d2
7 changed files with 31 additions and 25 deletions

View File

@ -19,7 +19,6 @@
@interface RCTTextField : RCTTextInput @interface RCTTextField : RCTTextInput
@property (nonatomic, assign) BOOL caretHidden; @property (nonatomic, assign) BOOL caretHidden;
@property (nonatomic, assign) BOOL selectTextOnFocus;
@property (nonatomic, strong) NSNumber *maxLength; @property (nonatomic, strong) NSNumber *maxLength;
@property (nonatomic, copy) RCTDirectEventBlock onSelectionChange; @property (nonatomic, copy) RCTDirectEventBlock onSelectionChange;

View File

@ -162,11 +162,6 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithCoder:(NSCoder *)aDecoder)
[self sendSelectionEvent]; [self sendSelectionEvent];
} }
- (BOOL)textInputShouldBeginEditing
{
return YES;
}
- (void)textInputDidBeginEditing - (void)textInputDidBeginEditing
{ {
[_eventDispatcher sendTextEventWithType:RCTTextEventTypeFocus [_eventDispatcher sendTextEventWithType:RCTTextEventTypeFocus
@ -174,14 +169,6 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithCoder:(NSCoder *)aDecoder)
text:_backedTextInput.text text:_backedTextInput.text
key:nil key:nil
eventCount:_nativeEventCount]; eventCount:_nativeEventCount];
dispatch_async(dispatch_get_main_queue(), ^{
if (self->_selectTextOnFocus) {
[self->_backedTextInput selectAll:nil];
}
[self sendSelectionEvent];
});
} }
- (BOOL)textInputShouldEndEditing - (BOOL)textInputShouldEndEditing

View File

@ -42,11 +42,13 @@
@property (nonatomic, assign) NSInteger mostRecentEventCount; @property (nonatomic, assign) NSInteger mostRecentEventCount;
@property (nonatomic, assign) BOOL blurOnSubmit; @property (nonatomic, assign) BOOL blurOnSubmit;
@property (nonatomic, assign) BOOL selectTextOnFocus;
- (void)invalidateContentSize; - (void)invalidateContentSize;
// Temporary exposure of particial `RCTBackedTextInputDelegate` support. // Temporary exposure of particial `RCTBackedTextInputDelegate` support.
// In the future all methods of the protocol should move to this class. // In the future all methods of the protocol should move to this class.
- (BOOL)textInputShouldBeginEditing;
- (BOOL)textInputShouldReturn; - (BOOL)textInputShouldReturn;
- (void)textInputDidReturn; - (void)textInputDidReturn;

View File

@ -86,6 +86,17 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithFrame:(CGRect)frame)
#pragma mark - RCTBackedTextInputDelegate #pragma mark - RCTBackedTextInputDelegate
- (BOOL)textInputShouldBeginEditing
{
if (_selectTextOnFocus) {
dispatch_async(dispatch_get_main_queue(), ^{
[self.backedTextInputView selectAll:nil];
});
}
return YES;
}
- (BOOL)textInputShouldReturn - (BOOL)textInputShouldReturn
{ {
return _blurOnSubmit; return _blurOnSubmit;

View File

@ -21,7 +21,6 @@
@property (nonatomic, assign) UITextAutocorrectionType autocorrectionType; @property (nonatomic, assign) UITextAutocorrectionType autocorrectionType;
@property (nonatomic, assign) UITextSpellCheckingType spellCheckingType; @property (nonatomic, assign) UITextSpellCheckingType spellCheckingType;
@property (nonatomic, assign) BOOL clearTextOnFocus; @property (nonatomic, assign) BOOL clearTextOnFocus;
@property (nonatomic, assign) BOOL selectTextOnFocus;
@property (nonatomic, assign) BOOL automaticallyAdjustContentInsets; @property (nonatomic, assign) BOOL automaticallyAdjustContentInsets;
@property (nonatomic, copy) NSString *text; @property (nonatomic, copy) NSString *text;
@property (nonatomic, strong) UIColor *placeholderTextColor; @property (nonatomic, strong) UIColor *placeholderTextColor;

View File

@ -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 - (void)textInputDidBeginEditing
{ {
if (_clearTextOnFocus) { if (_clearTextOnFocus) {

View File

@ -684,6 +684,24 @@ exports.examples = [
selectTextOnFocus={true} selectTextOnFocus={true}
/> />
</WithLabel> </WithLabel>
<WithLabel label="clearTextOnFocus (multiline)">
<TextInput
placeholder="text is cleared on focus"
defaultValue="text is cleared on focus"
style={styles.default}
clearTextOnFocus={true}
multiline={true}
/>
</WithLabel>
<WithLabel label="selectTextOnFocus (multiline)">
<TextInput
placeholder="text is selected on focus"
defaultValue="text is selected on focus"
style={styles.default}
selectTextOnFocus={true}
multiline={true}
/>
</WithLabel>
</View> </View>
); );
} }