mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Fabric: Introducing BaseTextShadowNode::getAttributedString()
Summary: `BaseTextShadowNode::getAttributedString()` was replaced with simular method `BaseTextShadowNode::buildAttributedString()` which does same work with following differences: * Besides returning `AttributedString`, it retures an array of `Attachment`s elements of which points to `ShadowNode`s that form attachments; * Now we use single `AttributedString` to construct result instead of concatenation objects recurvily walking the tree. We will use the array of attachments later. Changelog: [Internal] Fabric-specific internal change. Reviewed By: sammy-SC Differential Revision: D20268048 fbshipit-source-id: 371c548826bdfd5c4f4b18915d68977724885ce6
This commit is contained in:
committed by
Facebook Github Bot
parent
dedf9372ca
commit
f18358dda6
@@ -11,7 +11,6 @@
|
||||
#include <react/components/text/RawTextShadowNode.h>
|
||||
#include <react/components/text/TextProps.h>
|
||||
#include <react/components/text/TextShadowNode.h>
|
||||
#include <react/debug/DebugStringConvertibleItem.h>
|
||||
#include <react/mounting/ShadowView.h>
|
||||
|
||||
namespace facebook {
|
||||
@@ -26,51 +25,53 @@ inline ShadowView shadowViewFromShadowNode(ShadowNode const &shadowNode) {
|
||||
return shadowView;
|
||||
}
|
||||
|
||||
AttributedString BaseTextShadowNode::getAttributedString(
|
||||
TextAttributes const &textAttributes,
|
||||
ShadowNode const &parentNode) {
|
||||
auto attributedString = AttributedString{};
|
||||
|
||||
void BaseTextShadowNode::buildAttributedString(
|
||||
TextAttributes const &baseTextAttributes,
|
||||
ShadowNode const &parentNode,
|
||||
AttributedString &outAttributedString,
|
||||
Attachments &outAttachments) {
|
||||
for (auto const &childNode : parentNode.getChildren()) {
|
||||
// RawShadowNode
|
||||
auto rawTextShadowNode =
|
||||
std::dynamic_pointer_cast<const RawTextShadowNode>(childNode);
|
||||
std::dynamic_pointer_cast<RawTextShadowNode const>(childNode);
|
||||
if (rawTextShadowNode) {
|
||||
auto fragment = AttributedString::Fragment{};
|
||||
fragment.string = rawTextShadowNode->getConcreteProps().text;
|
||||
fragment.textAttributes = textAttributes;
|
||||
fragment.textAttributes = baseTextAttributes;
|
||||
|
||||
// Storing a retaining pointer to `ParagraphShadowNode` inside
|
||||
// `attributedString` causes a retain cycle (besides that fact that we
|
||||
// don't need it at all). Storing a `ShadowView` instance instead of
|
||||
// `ShadowNode` should properly fix this problem.
|
||||
fragment.parentShadowView = shadowViewFromShadowNode(parentNode);
|
||||
attributedString.appendFragment(fragment);
|
||||
outAttributedString.appendFragment(fragment);
|
||||
continue;
|
||||
}
|
||||
|
||||
// TextShadowNode
|
||||
auto textShadowNode =
|
||||
std::dynamic_pointer_cast<const TextShadowNode>(childNode);
|
||||
std::dynamic_pointer_cast<TextShadowNode const>(childNode);
|
||||
if (textShadowNode) {
|
||||
auto localTextAttributes = textAttributes;
|
||||
auto localTextAttributes = baseTextAttributes;
|
||||
localTextAttributes.apply(
|
||||
textShadowNode->getConcreteProps().textAttributes);
|
||||
attributedString.appendAttributedString(
|
||||
textShadowNode->getAttributedString(
|
||||
localTextAttributes, *textShadowNode));
|
||||
buildAttributedString(
|
||||
localTextAttributes,
|
||||
*textShadowNode,
|
||||
outAttributedString,
|
||||
outAttachments);
|
||||
continue;
|
||||
}
|
||||
|
||||
// Any other kind of ShadowNode
|
||||
// Any *other* kind of ShadowNode
|
||||
auto fragment = AttributedString::Fragment{};
|
||||
fragment.string = AttributedString::Fragment::AttachmentCharacter();
|
||||
fragment.parentShadowView = shadowViewFromShadowNode(*childNode);
|
||||
fragment.textAttributes = textAttributes;
|
||||
attributedString.appendFragment(fragment);
|
||||
fragment.textAttributes = baseTextAttributes;
|
||||
outAttributedString.appendFragment(fragment);
|
||||
outAttachments.push_back(Attachment{
|
||||
childNode.get(), outAttributedString.getFragments().size() - 1});
|
||||
}
|
||||
|
||||
return attributedString;
|
||||
}
|
||||
|
||||
} // namespace react
|
||||
|
||||
Reference in New Issue
Block a user