2018-05-07 21:49:23 -07:00
|
|
|
/**
|
|
|
|
* 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 "ParagraphShadowNode.h"
|
|
|
|
|
2018-08-04 09:30:13 -07:00
|
|
|
#include "ParagraphLocalData.h"
|
2018-05-07 21:49:23 -07:00
|
|
|
|
|
|
|
namespace facebook {
|
|
|
|
namespace react {
|
|
|
|
|
2018-08-04 09:30:13 -07:00
|
|
|
const char ParagraphComponentName[] = "Paragraph";
|
2018-05-07 21:49:23 -07:00
|
|
|
|
|
|
|
AttributedString ParagraphShadowNode::getAttributedString() const {
|
2018-07-15 16:46:24 -07:00
|
|
|
if (!cachedAttributedString_.has_value()) {
|
|
|
|
cachedAttributedString_ =
|
|
|
|
BaseTextShadowNode::getAttributedString(getProps()->textAttributes, getChildren());
|
|
|
|
}
|
|
|
|
|
|
|
|
return cachedAttributedString_.value();
|
2018-05-07 21:49:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
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(
|
|
|
|
getAttributedString(),
|
2018-05-14 15:43:28 -07:00
|
|
|
getProps()->paragraphAttributes,
|
2018-05-07 21:49:23 -07:00
|
|
|
layoutConstraints
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ParagraphShadowNode::layout(LayoutContext layoutContext) {
|
|
|
|
updateLocalData();
|
2018-08-04 09:30:13 -07:00
|
|
|
ConcreteViewShadowNode::layout(layoutContext);
|
2018-05-07 21:49:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace react
|
|
|
|
} // namespace facebook
|