mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
7186a65b13
Summary: This is another step on the journey of removing `enable_shared_from_this`. It's unclear why we used that before but it's clear now that using shared_ptr here is not necessary because all computation around happens inside the single callstack, so by definition we don't have object life-time concerns here. Changelog: [Internal] Small Fabric-specific optimization. Reviewed By: sammy-SC Differential Revision: D17973957 fbshipit-source-id: 09a65c78e22083ed21b041240307f4858379cc60
67 lines
2.2 KiB
C++
67 lines
2.2 KiB
C++
/*
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
*
|
|
* 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 <react/components/text/RawTextProps.h>
|
|
#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 {
|
|
namespace react {
|
|
|
|
AttributedString BaseTextShadowNode::getAttributedString(
|
|
TextAttributes const &textAttributes,
|
|
ShadowNode const &parentNode) {
|
|
auto attributedString = AttributedString{};
|
|
|
|
for (auto const &childNode : parentNode.getChildren()) {
|
|
// RawShadowNode
|
|
auto rawTextShadowNode =
|
|
std::dynamic_pointer_cast<const RawTextShadowNode>(childNode);
|
|
if (rawTextShadowNode) {
|
|
auto fragment = AttributedString::Fragment{};
|
|
fragment.string = rawTextShadowNode->getProps()->text;
|
|
fragment.textAttributes = textAttributes;
|
|
|
|
// 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 = ShadowView(parentNode);
|
|
attributedString.appendFragment(fragment);
|
|
continue;
|
|
}
|
|
|
|
// TextShadowNode
|
|
auto textShadowNode =
|
|
std::dynamic_pointer_cast<const TextShadowNode>(childNode);
|
|
if (textShadowNode) {
|
|
auto localTextAttributes = textAttributes;
|
|
localTextAttributes.apply(textShadowNode->getProps()->textAttributes);
|
|
attributedString.appendAttributedString(
|
|
textShadowNode->getAttributedString(
|
|
localTextAttributes, *textShadowNode));
|
|
continue;
|
|
}
|
|
|
|
// Any other kind of ShadowNode
|
|
auto fragment = AttributedString::Fragment{};
|
|
fragment.shadowView = ShadowView(*childNode);
|
|
fragment.textAttributes = textAttributes;
|
|
attributedString.appendFragment(fragment);
|
|
}
|
|
|
|
return attributedString;
|
|
}
|
|
|
|
} // namespace react
|
|
} // namespace facebook
|