mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-03-06 22:37:14 +08:00
Fabric: Text measuring: Handling the case where the string is empty
Summary: Surprisingly, we have some significant amount of text measuring requests where the string is empty. So, there is no need to go to platform specific layer to find that the size of those strings is zero. Reviewed By: mdvacca Differential Revision: D14297315 fbshipit-source-id: bf84cf27d5c0893262e8b27da8ff42fc77bcd6c5
This commit is contained in:
committed by
Facebook Github Bot
parent
c61398d8f9
commit
24c0702818
@@ -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_;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user