mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-06-17 01:59:25 +08:00
Fabric: TextAttributes::defaultTextAttributes()
Summary: An `AttributedString` object generated by a cross-platform layer of React Native must have already resolved text styles to make the actual resulting text identical across platforms. To do so we have to have a unified default. Reviewed By: sahrens Differential Revision: D10287725 fbshipit-source-id: e8c62b33496be34146182baccd0009d3624a7fe5
This commit is contained in:
committed by
Facebook Github Bot
parent
057438a103
commit
07d8b06d41
@@ -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
|
||||
|
||||
@@ -27,6 +27,13 @@ using SharedTextAttributes = std::shared_ptr<const TextAttributes>;
|
||||
|
||||
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
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user