Skip to content

Commit

Permalink
AndroidTextInput: don't override text with default/placeholder text e…
Browse files Browse the repository at this point in the history
…xcept for measurement

Summary:
In C++ we return default/placeholder text instead of text in `getAttributedString` so that measurement is correct. This is fine but we shouldn't actually set the attributedString on the ReactEditText view.

Changelog: [Internal]

Reviewed By: mdvacca

Differential Revision: D18672369

fbshipit-source-id: 1bb5cddda3cf78f2cff6f805e67c8994ab32ee7c
  • Loading branch information
JoshuaGross authored and facebook-github-bot committed Nov 27, 2019
1 parent da5ea02 commit 98b8a17
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,16 @@ void AndroidTextInputShadowNode::setContextContainer(
contextContainer_ = contextContainer;
}

AttributedString AndroidTextInputShadowNode::getAttributedString() const {
AttributedString AndroidTextInputShadowNode::getAttributedString(
bool usePlaceholders) const {
auto textAttributes = TextAttributes::defaultTextAttributes();
textAttributes.apply(getProps()->textAttributes);

// Use BaseTextShadowNode to get attributed string from children
{
auto const &attributedString =
BaseTextShadowNode::getAttributedString(textAttributes, *this);
if (!attributedString.isEmpty()) {
if (!attributedString.isEmpty() || !usePlaceholders) {
return attributedString;
}
}
Expand Down Expand Up @@ -69,7 +70,7 @@ void AndroidTextInputShadowNode::setTextLayoutManager(
void AndroidTextInputShadowNode::updateStateIfNeeded() {
ensureUnsealed();

auto attributedString = getAttributedString();
auto attributedString = getAttributedString(false);
auto const &state = getStateData();

assert(textLayoutManager_);
Expand All @@ -92,7 +93,7 @@ void AndroidTextInputShadowNode::updateStateIfNeeded() {

Size AndroidTextInputShadowNode::measure(
LayoutConstraints layoutConstraints) const {
AttributedString attributedString = getAttributedString();
AttributedString attributedString = getAttributedString(true);

if (attributedString.isEmpty()) {
return {0, 0};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class AndroidTextInputShadowNode : public ConcreteViewShadowNode<
/*
* Returns a `AttributedString` which represents text content of the node.
*/
AttributedString getAttributedString() const;
AttributedString getAttributedString(bool usePlaceholders) const;

/*
* Associates a shared TextLayoutManager with the node.
Expand Down

0 comments on commit 98b8a17

Please sign in to comment.