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 коммит произвёл Facebook Github Bot
Родитель 8f93ce680d
Коммит cb96f1d5d2
7 изменённых файлов: 31 добавлений и 25 удалений

Просмотреть файл

@ -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;

Просмотреть файл

@ -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

Просмотреть файл

@ -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;

Просмотреть файл

@ -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;

Просмотреть файл

@ -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;

Просмотреть файл

@ -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) {

Просмотреть файл

@ -684,6 +684,24 @@ exports.examples = [
selectTextOnFocus={true}
/>
</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>
);
}