mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
f18358dda6
Summary: `BaseTextShadowNode::getAttributedString()` was replaced with simular method `BaseTextShadowNode::buildAttributedString()` which does same work with following differences: * Besides returning `AttributedString`, it retures an array of `Attachment`s elements of which points to `ShadowNode`s that form attachments; * Now we use single `AttributedString` to construct result instead of concatenation objects recurvily walking the tree. We will use the array of attachments later. Changelog: [Internal] Fabric-specific internal change. Reviewed By: sammy-SC Differential Revision: D20268048 fbshipit-source-id: 371c548826bdfd5c4f4b18915d68977724885ce6
83 lines
2.3 KiB
C++
83 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 "ParagraphShadowNode.h"
|
|
|
|
#include <react/attributedstring/AttributedStringBox.h>
|
|
#include "ParagraphState.h"
|
|
|
|
namespace facebook {
|
|
namespace react {
|
|
|
|
char const ParagraphComponentName[] = "Paragraph";
|
|
|
|
AttributedString ParagraphShadowNode::getAttributedString() const {
|
|
if (!cachedAttributedString_.has_value()) {
|
|
auto textAttributes = TextAttributes::defaultTextAttributes();
|
|
textAttributes.apply(getConcreteProps().textAttributes);
|
|
|
|
auto attributedString = AttributedString{};
|
|
auto attachments = Attachments{};
|
|
BaseTextShadowNode::buildAttributedString(
|
|
textAttributes, *this, attributedString, attachments);
|
|
|
|
cachedAttributedString_ = attributedString;
|
|
}
|
|
|
|
return cachedAttributedString_.value();
|
|
}
|
|
|
|
void ParagraphShadowNode::setTextLayoutManager(
|
|
SharedTextLayoutManager textLayoutManager) {
|
|
ensureUnsealed();
|
|
textLayoutManager_ = textLayoutManager;
|
|
}
|
|
|
|
void ParagraphShadowNode::updateStateIfNeeded() {
|
|
ensureUnsealed();
|
|
|
|
auto attributedString = getAttributedString();
|
|
auto const &state = getStateData();
|
|
|
|
assert(textLayoutManager_);
|
|
assert(
|
|
(!state.layoutManager || state.layoutManager == textLayoutManager_) &&
|
|
"`StateData` refers to a different `TextLayoutManager`");
|
|
|
|
if (state.attributedString == attributedString &&
|
|
state.layoutManager == textLayoutManager_) {
|
|
return;
|
|
}
|
|
|
|
setStateData(ParagraphState{attributedString,
|
|
getConcreteProps().paragraphAttributes,
|
|
textLayoutManager_});
|
|
}
|
|
|
|
#pragma mark - LayoutableShadowNode
|
|
|
|
Size ParagraphShadowNode::measure(LayoutConstraints layoutConstraints) const {
|
|
AttributedString attributedString = getAttributedString();
|
|
|
|
if (attributedString.isEmpty()) {
|
|
return layoutConstraints.clamp({0, 0});
|
|
}
|
|
|
|
return textLayoutManager_->measure(
|
|
AttributedStringBox{attributedString},
|
|
getConcreteProps().paragraphAttributes,
|
|
layoutConstraints);
|
|
}
|
|
|
|
void ParagraphShadowNode::layout(LayoutContext layoutContext) {
|
|
updateStateIfNeeded();
|
|
ConcreteViewShadowNode::layout(layoutContext);
|
|
}
|
|
|
|
} // namespace react
|
|
} // namespace facebook
|