diff --git a/ReactCommon/fabric/attributedstring/TextAttributes.cpp b/ReactCommon/fabric/attributedstring/TextAttributes.cpp index ee31969dd14..43f87235a09 100644 --- a/ReactCommon/fabric/attributedstring/TextAttributes.cpp +++ b/ReactCommon/fabric/attributedstring/TextAttributes.cpp @@ -149,6 +149,18 @@ bool TextAttributes::operator!=(const TextAttributes &rhs) const { return !(*this == rhs); } +TextAttributes TextAttributes::defaultTextAttributes() { + static auto textAttributes = [] { + auto textAttributes = TextAttributes{}; + // Non-obvious (can be different among platforms) default text attributes. + textAttributes.foregroundColor = blackColor(); + textAttributes.backgroundColor = clearColor(); + textAttributes.fontSize = 12.0; + return textAttributes; + }(); + return textAttributes; +} + #pragma mark - DebugStringConvertible #if RN_DEBUG_STRING_CONVERTIBLE diff --git a/ReactCommon/fabric/attributedstring/TextAttributes.h b/ReactCommon/fabric/attributedstring/TextAttributes.h index cfd103a7893..e0acba57681 100644 --- a/ReactCommon/fabric/attributedstring/TextAttributes.h +++ b/ReactCommon/fabric/attributedstring/TextAttributes.h @@ -27,6 +27,13 @@ using SharedTextAttributes = std::shared_ptr; class TextAttributes : public DebugStringConvertible { public: + /* + * Returns TextAttribute object which has actual default attribute values + * (e.g. `foregroundColor = black`), in oppose to TextAttribute's default + * constructor which creates an object with nulled attributes. + */ + static TextAttributes defaultTextAttributes(); + #pragma mark - Fields // Color diff --git a/ReactCommon/fabric/components/text/paragraph/ParagraphShadowNode.cpp b/ReactCommon/fabric/components/text/paragraph/ParagraphShadowNode.cpp index 640a8cad40f..245dcee932f 100644 --- a/ReactCommon/fabric/components/text/paragraph/ParagraphShadowNode.cpp +++ b/ReactCommon/fabric/components/text/paragraph/ParagraphShadowNode.cpp @@ -16,8 +16,11 @@ const char ParagraphComponentName[] = "Paragraph"; AttributedString ParagraphShadowNode::getAttributedString() const { if (!cachedAttributedString_.has_value()) { + auto textAttributes = TextAttributes::defaultTextAttributes(); + textAttributes.apply(getProps()->textAttributes); + cachedAttributedString_ = BaseTextShadowNode::getAttributedString( - getProps()->textAttributes, shared_from_this()); + textAttributes, shared_from_this()); } return cachedAttributedString_.value();