react-native/ReactCommon/fabric/text/basetext/BaseTextShadowNode.cpp
Valentin Shergin eabf29e320 Fabric: Getting rid of many auto &&
Summary:
@public
After reading about move-semantic and rvalue refs I realized that we (I) definitely overuse  `auto &&` (aka universal reference) construction. Even if this is harmless, does not look good and idiomatic.
Whenever I used that from a semantical point of view I always meant  "I need an alias for this" which is actually "read-only reference" which is `const auto &`.
This is also fit good to our policy where "everything is const (immutable) by default".
Hence I change that to how it should be.

Reviewed By: fkgozali

Differential Revision: D8475637

fbshipit-source-id: 0a691ededa0e798db8ffa053bff0f400913ab7b8
2018-06-22 07:32:49 -07:00

60 lines
1.8 KiB
C++

/**
* 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 (const auto &childNode : *childNodes) {
// RawShadowNode
SharedRawTextShadowNode rawTextShadowNode = std::dynamic_pointer_cast<const RawTextShadowNode>(childNode);
if (rawTextShadowNode) {
AttributedString::Fragment fragment;
fragment.string = rawTextShadowNode->getProps()->text;
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()->textAttributes);
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