mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-08 09:37:21 +08:00
Summary: Consider this: * ParagraphShadowNode retains LocalData, * LocalData contains AttributedString, * AttributedString contains Fragments, * Fragment can contain a pointer to parent shadow node, so it can be the ParagraphShadowNode. In this case it's a retain cycle. We actually don't need to store pointers to not TextShadowNodes, so we don't now. Later, after we fully migrate to ShadowView, we can remove this condition because it will become harmless. Reviewed By: sahrens Differential Revision: D13196885 fbshipit-source-id: d386ce0a067df0a72e6619d62d56038aaf80eccb
69 lines
2.3 KiB
C++
69 lines
2.3 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>
|
|
|
|
namespace facebook {
|
|
namespace react {
|
|
|
|
AttributedString BaseTextShadowNode::getAttributedString(
|
|
const TextAttributes &textAttributes,
|
|
const SharedShadowNode &parentNode) const {
|
|
auto attributedString = AttributedString{};
|
|
|
|
for (const auto &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.parentShadowNode =
|
|
std::dynamic_pointer_cast<const TextShadowNode>(parentNode)
|
|
? parentNode
|
|
: nullptr;
|
|
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.shadowNode = childNode;
|
|
fragment.textAttributes = textAttributes;
|
|
attributedString.appendFragment(fragment);
|
|
}
|
|
|
|
return attributedString;
|
|
}
|
|
|
|
} // namespace react
|
|
} // namespace facebook
|