mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
90ada5abb1
Summary: This diff changes API we use to measure text. Previously, a platform-specific measure infra returned just the size of the text, now it returns the size and an array of frames that describe where attachments are placed. Changelog: [Internal] Fabric-specific internal change. Reviewed By: sammy-SC Differential Revision: D20268041 fbshipit-source-id: 7c065607b6af18a36318db0aab24dad0f171d33a
88 lines
2.3 KiB
C++
88 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";
|
|
|
|
ParagraphShadowNode::Content const &ParagraphShadowNode::getContent() const {
|
|
if (content_.has_value()) {
|
|
return content_.value();
|
|
}
|
|
|
|
ensureUnsealed();
|
|
|
|
auto textAttributes = TextAttributes::defaultTextAttributes();
|
|
textAttributes.apply(getConcreteProps().textAttributes);
|
|
|
|
auto attributedString = AttributedString{};
|
|
auto attachments = Attachments{};
|
|
buildAttributedString(textAttributes, *this, attributedString, attachments);
|
|
|
|
content_ = Content{
|
|
attributedString, getConcreteProps().paragraphAttributes, attachments};
|
|
|
|
return content_.value();
|
|
}
|
|
|
|
void ParagraphShadowNode::setTextLayoutManager(
|
|
SharedTextLayoutManager textLayoutManager) {
|
|
ensureUnsealed();
|
|
textLayoutManager_ = textLayoutManager;
|
|
}
|
|
|
|
void ParagraphShadowNode::updateStateIfNeeded(Content const &content) {
|
|
ensureUnsealed();
|
|
|
|
auto &state = getStateData();
|
|
|
|
assert(textLayoutManager_);
|
|
assert(
|
|
(!state.layoutManager || state.layoutManager == textLayoutManager_) &&
|
|
"`StateData` refers to a different `TextLayoutManager`");
|
|
|
|
if (state.attributedString == content.attributedString &&
|
|
state.layoutManager == textLayoutManager_) {
|
|
return;
|
|
}
|
|
|
|
setStateData(ParagraphState{content.attributedString,
|
|
content.paragraphAttributes,
|
|
textLayoutManager_});
|
|
}
|
|
|
|
#pragma mark - LayoutableShadowNode
|
|
|
|
Size ParagraphShadowNode::measure(LayoutConstraints layoutConstraints) const {
|
|
auto content = getContent();
|
|
|
|
if (content.attributedString.isEmpty()) {
|
|
return layoutConstraints.clamp({0, 0});
|
|
}
|
|
|
|
return textLayoutManager_
|
|
->measure(
|
|
AttributedStringBox{content.attributedString},
|
|
content.paragraphAttributes,
|
|
layoutConstraints)
|
|
.size;
|
|
}
|
|
|
|
void ParagraphShadowNode::layout(LayoutContext layoutContext) {
|
|
updateStateIfNeeded(getContent());
|
|
ConcreteViewShadowNode::layout(layoutContext);
|
|
}
|
|
|
|
} // namespace react
|
|
} // namespace facebook
|