Files
react-native/ReactCommon/fabric/components/text/paragraph/ParagraphShadowNode.cpp
Valentin Shergin 07d8b06d41 Fabric: TextAttributes::defaultTextAttributes()
Summary: An `AttributedString` object generated by a cross-platform layer of React Native must have already resolved text styles to make the actual resulting text identical across platforms. To do so we have to have a unified default.

Reviewed By: sahrens

Differential Revision: D10287725

fbshipit-source-id: e8c62b33496be34146182baccd0009d3624a7fe5
2018-10-15 23:25:47 -07:00

61 lines
1.6 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 "ParagraphShadowNode.h"
#include "ParagraphLocalData.h"
namespace facebook {
namespace react {
const char ParagraphComponentName[] = "Paragraph";
AttributedString ParagraphShadowNode::getAttributedString() const {
if (!cachedAttributedString_.has_value()) {
auto textAttributes = TextAttributes::defaultTextAttributes();
textAttributes.apply(getProps()->textAttributes);
cachedAttributedString_ = BaseTextShadowNode::getAttributedString(
textAttributes, shared_from_this());
}
return cachedAttributedString_.value();
}
void ParagraphShadowNode::setTextLayoutManager(
SharedTextLayoutManager textLayoutManager) {
ensureUnsealed();
textLayoutManager_ = textLayoutManager;
}
void ParagraphShadowNode::updateLocalData() {
ensureUnsealed();
auto localData = std::make_shared<ParagraphLocalData>();
localData->setAttributedString(getAttributedString());
localData->setTextLayoutManager(textLayoutManager_);
setLocalData(localData);
}
#pragma mark - LayoutableShadowNode
Size ParagraphShadowNode::measure(LayoutConstraints layoutConstraints) const {
return textLayoutManager_->measure(
getTag(),
getAttributedString(),
getProps()->paragraphAttributes,
layoutConstraints);
}
void ParagraphShadowNode::layout(LayoutContext layoutContext) {
updateLocalData();
ConcreteViewShadowNode::layout(layoutContext);
}
} // namespace react
} // namespace facebook