AndroidTextInput: don't override text with default/placeholder text except 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
This commit is contained in:
Joshua Gross
2019-11-27 12:55:48 -08:00
committed by Facebook Github Bot
parent da5ea0215a
commit 98b8a17645
2 changed files with 6 additions and 5 deletions
@@ -30,7 +30,8 @@ void AndroidTextInputShadowNode::setContextContainer(
contextContainer_ = contextContainer;
}
AttributedString AndroidTextInputShadowNode::getAttributedString() const {
AttributedString AndroidTextInputShadowNode::getAttributedString(
bool usePlaceholders) const {
auto textAttributes = TextAttributes::defaultTextAttributes();
textAttributes.apply(getProps()->textAttributes);
@@ -38,7 +39,7 @@ AttributedString AndroidTextInputShadowNode::getAttributedString() const {
{
auto const &attributedString =
BaseTextShadowNode::getAttributedString(textAttributes, *this);
if (!attributedString.isEmpty()) {
if (!attributedString.isEmpty() || !usePlaceholders) {
return attributedString;
}
}
@@ -69,7 +70,7 @@ void AndroidTextInputShadowNode::setTextLayoutManager(
void AndroidTextInputShadowNode::updateStateIfNeeded() {
ensureUnsealed();
auto attributedString = getAttributedString();
auto attributedString = getAttributedString(false);
auto const &state = getStateData();
assert(textLayoutManager_);
@@ -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};