Return AttributedString for placeholder text if text is empty

Summary:
In AndroidTextInput ShadowNode, return AttributedString for placeholder text if text is empty. This ensures that empty TextInputs will have non-zero height.

Changelog: [Internal]

Reviewed By: mdvacca

Differential Revision: D18623063

fbshipit-source-id: 2eec2b794b526e8ff5435352e20ccb659358fc84
This commit is contained in:
Joshua Gross 2019-11-20 18:38:17 -08:00 коммит произвёл Facebook Github Bot
Родитель 222a0895d9
Коммит 9c5b26639a
1 изменённых файлов: 23 добавлений и 1 удалений

Просмотреть файл

@ -35,7 +35,29 @@ AttributedString AndroidTextInputShadowNode::getAttributedString() const {
textAttributes.apply(getProps()->textAttributes);
// Use BaseTextShadowNode to get attributed string from children
return BaseTextShadowNode::getAttributedString(textAttributes, *this);
{
auto const &attributedString =
BaseTextShadowNode::getAttributedString(textAttributes, *this);
if (!attributedString.isEmpty()) {
return std::move(attributedString);
}
}
// Return placeholder text instead, if text was empty.
auto placeholderAttributedString = AttributedString{};
auto fragment = AttributedString::Fragment{};
fragment.string = getProps()->placeholder;
// For measurement purposes, we want to make sure that there's at least a
// single character in the string so that the measured height is greater than
// zero. Otherwise, empty TextInputs with no placeholder don't display at all.
if (fragment.string == "") {
fragment.string = " ";
}
fragment.textAttributes = textAttributes;
fragment.parentShadowView = ShadowView(*this);
placeholderAttributedString.appendFragment(fragment);
return placeholderAttributedString;
}
#pragma mark - LayoutableShadowNode