Skip to content

Commit

Permalink
Native changes for TextInput.setSelection method
Browse files Browse the repository at this point in the history
Summary:
Native changes in preparation for adding a `setSelection` imperative method to `TextInput`.

Changelog: [Internal]

Reviewed By: JoshuaGross

Differential Revision: D31590771

fbshipit-source-id: eed40d1c2803fec713f2008ab8053a2812249715
  • Loading branch information
lyahdav authored and facebook-github-bot committed Nov 11, 2021
1 parent 2ae06df commit f249d21
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
4 changes: 3 additions & 1 deletion Libraries/Text/TextInput/RCTBaseTextInputViewManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,9 @@ - (void)setBridge:(RCTBridge *)bridge
}
RCTExecuteOnUIManagerQueue(^{
RCTBaseTextInputShadowView *shadowView = (RCTBaseTextInputShadowView *)[self.bridge.uiManager shadowViewForReactTag:viewTag];
[shadowView setText:value];
if (value) {
[shadowView setText:value];
}
[self.bridge.uiManager setNeedsLayout];
RCTExecuteOnMainQueue(^{
[view setSelectionStart:start selectionEnd:end];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ - (void)setTextAndSelection:(NSInteger)eventCount
return;
}
_comingFromJS = YES;
if (![value isEqualToString:_backedTextInputView.attributedText.string]) {
if (value && ![value isEqualToString:_backedTextInputView.attributedText.string]) {
NSAttributedString *attributedString =
[[NSAttributedString alloc] initWithString:value attributes:_backedTextInputView.defaultTextAttributes];
[self _setAttributedString:attributedString];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,16 +288,17 @@ public void receiveCommand(
return;
}

String text = args.getString(1);

int start = args.getInt(2);
int end = args.getInt(3);
if (end == UNSET) {
end = start;
}

reactEditText.maybeSetTextFromJS(
getReactTextUpdate(text, mostRecentEventCount, start, end));
if (!args.isNull(1)) {
String text = args.getString(1);
reactEditText.maybeSetTextFromJS(
getReactTextUpdate(text, mostRecentEventCount, start, end));
}
reactEditText.maybeSetSelection(mostRecentEventCount, start, end);
break;
}
Expand Down

0 comments on commit f249d21

Please sign in to comment.