Skip to content

Commit 98b8a17

Browse files
JoshuaGrossfacebook-github-bot
authored andcommitted
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
1 parent da5ea02 commit 98b8a17

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

ReactCommon/fabric/components/textinput/androidtextinput/AndroidTextInputShadowNode.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,16 @@ void AndroidTextInputShadowNode::setContextContainer(
3030
contextContainer_ = contextContainer;
3131
}
3232

33-
AttributedString AndroidTextInputShadowNode::getAttributedString() const {
33+
AttributedString AndroidTextInputShadowNode::getAttributedString(
34+
bool usePlaceholders) const {
3435
auto textAttributes = TextAttributes::defaultTextAttributes();
3536
textAttributes.apply(getProps()->textAttributes);
3637

3738
// Use BaseTextShadowNode to get attributed string from children
3839
{
3940
auto const &attributedString =
4041
BaseTextShadowNode::getAttributedString(textAttributes, *this);
41-
if (!attributedString.isEmpty()) {
42+
if (!attributedString.isEmpty() || !usePlaceholders) {
4243
return attributedString;
4344
}
4445
}
@@ -69,7 +70,7 @@ void AndroidTextInputShadowNode::setTextLayoutManager(
6970
void AndroidTextInputShadowNode::updateStateIfNeeded() {
7071
ensureUnsealed();
7172

72-
auto attributedString = getAttributedString();
73+
auto attributedString = getAttributedString(false);
7374
auto const &state = getStateData();
7475

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

9394
Size AndroidTextInputShadowNode::measure(
9495
LayoutConstraints layoutConstraints) const {
95-
AttributedString attributedString = getAttributedString();
96+
AttributedString attributedString = getAttributedString(true);
9697

9798
if (attributedString.isEmpty()) {
9899
return {0, 0};

ReactCommon/fabric/components/textinput/androidtextinput/AndroidTextInputShadowNode.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class AndroidTextInputShadowNode : public ConcreteViewShadowNode<
3737
/*
3838
* Returns a `AttributedString` which represents text content of the node.
3939
*/
40-
AttributedString getAttributedString() const;
40+
AttributedString getAttributedString(bool usePlaceholders) const;
4141

4242
/*
4343
* Associates a shared TextLayoutManager with the node.

0 commit comments

Comments
 (0)