From 98b8a176458806172441c55d3754b2e9ad76d981 Mon Sep 17 00:00:00 2001 From: Joshua Gross Date: Wed, 27 Nov 2019 12:53:14 -0800 Subject: [PATCH] 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 --- .../androidtextinput/AndroidTextInputShadowNode.cpp | 9 +++++---- .../androidtextinput/AndroidTextInputShadowNode.h | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/ReactCommon/fabric/components/textinput/androidtextinput/AndroidTextInputShadowNode.cpp b/ReactCommon/fabric/components/textinput/androidtextinput/AndroidTextInputShadowNode.cpp index fde3732774b..617e19c06f6 100644 --- a/ReactCommon/fabric/components/textinput/androidtextinput/AndroidTextInputShadowNode.cpp +++ b/ReactCommon/fabric/components/textinput/androidtextinput/AndroidTextInputShadowNode.cpp @@ -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}; diff --git a/ReactCommon/fabric/components/textinput/androidtextinput/AndroidTextInputShadowNode.h b/ReactCommon/fabric/components/textinput/androidtextinput/AndroidTextInputShadowNode.h index 0576be16ca6..796260c8c85 100644 --- a/ReactCommon/fabric/components/textinput/androidtextinput/AndroidTextInputShadowNode.h +++ b/ReactCommon/fabric/components/textinput/androidtextinput/AndroidTextInputShadowNode.h @@ -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.