Files
react-native/ReactCommon/fabric/components/text/basetext/BaseTextShadowNode.cpp
T
Valentin Shergin 967c9dc7b1 Fabric: ConcreteShadowNode::getProps() was renamed to getConcreteProps() and got new return type.
Summary:
Having the overridden function that returns a different type is apparently not a good idea (and might cause bugs and unexpected behavior), so it was renamed. The function also got a new return type (`const &` instead of `std::shared_ptr`) for simplicity, better performance, and smaller code size.

Changelog: [Internal] Fabric-specific internal change.

Reviewed By: JoshuaGross

Differential Revision: D19837694

fbshipit-source-id: b7a96424bd040409371724907b3fb3931cd8a2e8
2020-02-13 21:07:30 -08:00

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>
#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->getConcreteProps().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->getConcreteProps().textAttributes);
attributedString.appendAttributedString(
textShadowNode->getAttributedString(
localTextAttributes, *textShadowNode));
continue;
}
// Any other kind of ShadowNode
auto fragment = AttributedString::Fragment{};
fragment.string = AttributedString::Fragment::AttachmentCharacter();
fragment.parentShadowView = ShadowView(*childNode);
fragment.textAttributes = textAttributes;
attributedString.appendFragment(fragment);
}
return attributedString;
}
} // namespace react
} // namespace facebook