forked from facebook/react-native
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fabric/Text: <Paragraph> is now supporting text attributes
Summary: I was shamed by Sebastian's sebmarkbage concerns (totally unrelated to this topic) about introducing another level of indirection into the system and decided to change my original plan not to support text attributes for the <Paragraph> component. So, now <Paragraph> shares <View>, <Text> and <Paragraph> itself capabilities. That reduces the minimum amount of required components for trivial text fragment from three (Paragraph, Text, RawText) to two (Paragraph and RawText). Special thanks for C++ for supporting multiple inheritance. Reviewed By: mdvacca Differential Revision: D7785889 fbshipit-source-id: dd9f2e2650bfbfd76d7d4b538adaf409f9429df3
- Loading branch information
1 parent
9ea7957
commit d9ff176
Showing
19 changed files
with
268 additions
and
147 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/** | ||
* Copyright (c) 2015-present, Facebook, Inc. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
#include "BaseTextProps.h" | ||
|
||
#include <fabric/attributedstring/textValuesConversions.h> | ||
#include <fabric/core/propsConversions.h> | ||
#include <fabric/debug/DebugStringConvertibleItem.h> | ||
#include <fabric/graphics/graphicValuesConversions.h> | ||
#include <fabric/text/propsConversions.h> | ||
|
||
namespace facebook { | ||
namespace react { | ||
|
||
void BaseTextProps::apply(const RawProps &rawProps) { | ||
// Color | ||
applyRawProp(rawProps, "color", textAttributes_.foregroundColor); | ||
applyRawProp(rawProps, "backgroundColor", textAttributes_.backgroundColor); | ||
applyRawProp(rawProps, "opacity", textAttributes_.opacity); | ||
|
||
// Font | ||
applyRawProp(rawProps, "fontFamily", textAttributes_.fontFamily); | ||
applyRawProp(rawProps, "fontSize", textAttributes_.fontSize); | ||
applyRawProp(rawProps, "fontSizeMultiplier", textAttributes_.fontSizeMultiplier); | ||
applyRawProp(rawProps, "fontWeight", textAttributes_.fontWeight); | ||
applyRawProp(rawProps, "fontStyle", textAttributes_.fontStyle); | ||
applyRawProp(rawProps, "fontVariant", textAttributes_.fontVariant); | ||
applyRawProp(rawProps, "allowFontScaling", textAttributes_.allowFontScaling); | ||
applyRawProp(rawProps, "letterSpacing", textAttributes_.letterSpacing); | ||
|
||
// Paragraph | ||
applyRawProp(rawProps, "lineHeight", textAttributes_.lineHeight); | ||
applyRawProp(rawProps, "alignment", textAttributes_.alignment); | ||
applyRawProp(rawProps, "baseWritingDirection", textAttributes_.baseWritingDirection); | ||
|
||
// Decoration | ||
applyRawProp(rawProps, "textDecorationColor", textAttributes_.textDecorationColor); | ||
applyRawProp(rawProps, "textDecorationLineType", textAttributes_.textDecorationLineType); | ||
applyRawProp(rawProps, "textDecorationLineStyle", textAttributes_.textDecorationLineStyle); | ||
applyRawProp(rawProps, "textDecorationLinePattern", textAttributes_.textDecorationLinePattern); | ||
|
||
// Shadow | ||
applyRawProp(rawProps, "textShadowOffset", textAttributes_.textShadowOffset); | ||
applyRawProp(rawProps, "textShadowRadius", textAttributes_.textShadowRadius); | ||
applyRawProp(rawProps, "textShadowColor", textAttributes_.textShadowColor); | ||
|
||
// Special | ||
applyRawProp(rawProps, "isHighlighted", textAttributes_.isHighlighted); | ||
} | ||
|
||
#pragma mark - Getters | ||
|
||
TextAttributes BaseTextProps::getTextAttributes() const { | ||
return textAttributes_; | ||
} | ||
|
||
#pragma mark - DebugStringConvertible | ||
|
||
SharedDebugStringConvertibleList BaseTextProps::getDebugProps() const { | ||
SharedDebugStringConvertibleList list = {}; | ||
|
||
auto textAttributesPropsList = textAttributes_.getDebugProps(); | ||
std::move(textAttributesPropsList.begin(), textAttributesPropsList.end(), std::back_inserter(list)); | ||
|
||
return list; | ||
} | ||
|
||
} // namespace react | ||
} // namespace facebook |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/** | ||
* Copyright (c) 2015-present, Facebook, Inc. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <fabric/attributedstring/TextAttributes.h> | ||
#include <fabric/core/Props.h> | ||
#include <fabric/graphics/Color.h> | ||
#include <fabric/graphics/Geometry.h> | ||
|
||
namespace facebook { | ||
namespace react { | ||
|
||
/* | ||
* `Props`-like class which is used as a base class for all Props classes | ||
* that can have text attributes (such as Text and Paragraph). | ||
*/ | ||
class BaseTextProps { | ||
public: | ||
|
||
/* | ||
* Same semantic as `Props::apply(...)`. | ||
*/ | ||
void apply(const RawProps &rawProps); | ||
|
||
#pragma mark - Getters | ||
|
||
/* | ||
* Returns all props values as `TextAttributes` object. | ||
*/ | ||
TextAttributes getTextAttributes() const; | ||
|
||
#pragma mark - DebugStringConvertible (partially) | ||
|
||
SharedDebugStringConvertibleList getDebugProps() const; | ||
|
||
private: | ||
|
||
TextAttributes textAttributes_; | ||
}; | ||
|
||
} // namespace react | ||
} // namespace facebook | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/** | ||
* Copyright (c) 2015-present, Facebook, Inc. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
#include "BaseTextShadowNode.h" | ||
|
||
#include <fabric/debug/DebugStringConvertibleItem.h> | ||
|
||
#include "RawTextShadowNode.h" | ||
#include "RawTextProps.h" | ||
#include "TextShadowNode.h" | ||
#include "TextProps.h" | ||
|
||
namespace facebook { | ||
namespace react { | ||
|
||
AttributedString BaseTextShadowNode::getAttributedString( | ||
const TextAttributes &textAttributes, | ||
const SharedShadowNodeSharedList &childNodes | ||
) const { | ||
// TODO: Implement caching. | ||
|
||
AttributedString attributedString; | ||
|
||
for (auto &&childNode : *childNodes) { | ||
// RawShadowNode | ||
SharedRawTextShadowNode rawTextShadowNode = std::dynamic_pointer_cast<const RawTextShadowNode>(childNode); | ||
if (rawTextShadowNode) { | ||
AttributedString::Fragment fragment; | ||
fragment.string = rawTextShadowNode->getProps()->getText(); | ||
fragment.textAttributes = textAttributes; | ||
attributedString.appendFragment(fragment); | ||
continue; | ||
} | ||
|
||
// TextShadowNode | ||
SharedTextShadowNode textShadowNode = std::dynamic_pointer_cast<const TextShadowNode>(childNode); | ||
if (textShadowNode) { | ||
TextAttributes localTextAttributes = textAttributes; | ||
localTextAttributes.apply(textShadowNode->getProps()->getTextAttributes()); | ||
attributedString.appendAttributedString(textShadowNode->getAttributedString(localTextAttributes, textShadowNode->getChildren())); | ||
continue; | ||
} | ||
|
||
// Any other kind of ShadowNode | ||
AttributedString::Fragment fragment; | ||
fragment.shadowNode = childNode; | ||
fragment.textAttributes = textAttributes; | ||
attributedString.appendFragment(fragment); | ||
} | ||
|
||
return attributedString; | ||
} | ||
|
||
} // namespace react | ||
} // namespace facebook |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/** | ||
* Copyright (c) 2015-present, Facebook, Inc. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <fabric/attributedstring/AttributedString.h> | ||
#include <fabric/attributedstring/TextAttributes.h> | ||
|
||
namespace facebook { | ||
namespace react { | ||
|
||
/* | ||
* Base class (one of) for shadow nodes that represents attributed text, | ||
* such as Text and Paragraph (but not RawText). | ||
*/ | ||
class BaseTextShadowNode { | ||
public: | ||
|
||
/* | ||
* Returns a `AttributedString` which represents text content of the node. | ||
*/ | ||
AttributedString getAttributedString( | ||
const TextAttributes &baseTextAttributes, | ||
const SharedShadowNodeSharedList &childNodes | ||
) const; | ||
}; | ||
|
||
} // namespace react | ||
} // namespace facebook |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.