Implement setTextAndSelection as view command in TextInput

Summary: Changelog: Add view command `TextInput.setTextAndSelection`

Reviewed By: JoshuaGross

Differential Revision: D19789675

fbshipit-source-id: 8eb19bd21b1e153c9639507016a9f452c5f835b0
This commit is contained in:
Samuel Susla
2020-02-07 14:10:28 -08:00
committed by Facebook Github Bot
parent 111f04ff11
commit fb8f5ea07f
3 changed files with 36 additions and 0 deletions
@@ -193,6 +193,25 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithFrame:(CGRect)frame)
}
}
- (void)setText:(NSString *__nullable)text
selectionStart:(NSInteger)start
selectionEnd:(NSInteger)end
{
if (text) {
NSMutableAttributedString *mutableString =
[[NSMutableAttributedString alloc] initWithAttributedString:self.backedTextInputView.attributedText];
[mutableString replaceCharactersInRange:NSMakeRange(0, mutableString.string.length) withString:text];
self.backedTextInputView.attributedText = mutableString;
}
UITextPosition *startPosition = [self.backedTextInputView positionFromPosition:self.backedTextInputView.beginningOfDocument
offset:start];
UITextPosition *endPosition = [self.backedTextInputView positionFromPosition:self.backedTextInputView.beginningOfDocument
offset:end];
UITextRange *range = [self.backedTextInputView textRangeFromPosition:startPosition toPosition:endPosition];
[self.backedTextInputView setSelectedTextRange:range notifyDelegate:NO];
}
- (void)setTextContentType:(NSString *)type
{
#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED)