diff --git a/ReactCommon/fabric/attributedstring/AttributedString.cpp b/ReactCommon/fabric/attributedstring/AttributedString.cpp index 5a85cb28d7e..67d2e78258a 100644 --- a/ReactCommon/fabric/attributedstring/AttributedString.cpp +++ b/ReactCommon/fabric/attributedstring/AttributedString.cpp @@ -34,11 +34,21 @@ bool Fragment::operator!=(const Fragment &rhs) const { void AttributedString::appendFragment(const Fragment &fragment) { ensureUnsealed(); + + if (fragment.string.empty()) { + return; + } + fragments_.push_back(fragment); } void AttributedString::prependFragment(const Fragment &fragment) { ensureUnsealed(); + + if (fragment.string.empty()) { + return; + } + fragments_.insert(fragments_.begin(), fragment); } @@ -72,6 +82,10 @@ std::string AttributedString::getString() const { return string; } +bool AttributedString::isEmpty() const { + return fragments_.empty(); +} + bool AttributedString::operator==(const AttributedString &rhs) const { return fragments_ == rhs.fragments_; } diff --git a/ReactCommon/fabric/attributedstring/AttributedString.h b/ReactCommon/fabric/attributedstring/AttributedString.h index 2178e62f820..6fc1abc2533 100644 --- a/ReactCommon/fabric/attributedstring/AttributedString.h +++ b/ReactCommon/fabric/attributedstring/AttributedString.h @@ -69,6 +69,11 @@ class AttributedString : public Sealable, public DebugStringConvertible { */ std::string getString() const; + /* + * Returns `true` if the string is empty (has no any fragments). + */ + bool isEmpty() const; + bool operator==(const AttributedString &rhs) const; bool operator!=(const AttributedString &rhs) const; diff --git a/ReactCommon/fabric/components/text/paragraph/ParagraphShadowNode.cpp b/ReactCommon/fabric/components/text/paragraph/ParagraphShadowNode.cpp index 13d80f4e9ac..028652ca5cb 100644 --- a/ReactCommon/fabric/components/text/paragraph/ParagraphShadowNode.cpp +++ b/ReactCommon/fabric/components/text/paragraph/ParagraphShadowNode.cpp @@ -59,6 +59,11 @@ void ParagraphShadowNode::updateLocalDataIfNeeded() { Size ParagraphShadowNode::measure(LayoutConstraints layoutConstraints) const { AttributedString attributedString = getAttributedString(); + + if (attributedString.isEmpty()) { + return {0, 0}; + } + const ParagraphAttributes paragraphAttributes = getProps()->paragraphAttributes;