Files
react-native/ReactCommon/fabric/components/text/paragraph/ParagraphShadowNode.cpp
David Vacca 5c0da011cb Add support to measure shadow nodes in the FabricUIManager
Summary: In this diff I added support to be able to measure C++ shadowNode in Android. As an example I implemented the measurement of TextViews

Reviewed By: shergin

Differential Revision: D9583972

fbshipit-source-id: 1344782d4c586c94a4576b18a4acfa4775e46952
2018-09-17 18:49:05 -07:00

58 lines
1.5 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()) {
cachedAttributedString_ =
BaseTextShadowNode::getAttributedString(getProps()->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