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:
parent
8f93ce680d
commit
cb96f1d5d2
|
@ -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>
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue