mirror of
https://github.com/facebook/react-native.git
synced 2026-11-18 20:19:07 +00:00
Revert D126131800: Keep paragraph content and measured layouts across unchanged clones
Differential Revision: D126131800 Original commit changeset: 88d934a7ecb1 Original Phabricator Diff: D126131800 fbshipit-source-id: ff9eed951bfe42643d196858d684c94dab1c8c14
This commit is contained in:
1 parent
6f6fa0ad9f
commit
ad2f451919
2 files changed
+12
-50
No files matched your search
+10
-47
@@ -59,23 +59,6 @@ ParagraphShadowNode::ParagraphShadowNode(
|
|||||||
const ShadowNodeFragment& fragment)
|
const ShadowNodeFragment& fragment)
|
||||||
: ConcreteViewShadowNode(sourceShadowNode, fragment) {
|
: ConcreteViewShadowNode(sourceShadowNode, fragment) {
|
||||||
initialize();
|
initialize();
|
||||||
// A revision with neither new props nor new children (e.g. one Yoga cloned
|
|
||||||
// because a sibling changed) renders the same content, so keep the
|
|
||||||
// attributed string and the layouts measured for it instead of rebuilding
|
|
||||||
// and re-measuring them. `getContent` drops both if the layout context they
|
|
||||||
// were built for no longer matches.
|
|
||||||
//
|
|
||||||
// Content with attachments is not kept: they point at the children the
|
|
||||||
// content was built from, and `layout` replaces those children with laid-out
|
|
||||||
// clones, so in a later revision the pointers would outlive the nodes.
|
|
||||||
if (fragment.props == nullptr && fragment.children == nullptr) {
|
|
||||||
const auto& source =
|
|
||||||
static_cast<const ParagraphShadowNode&>(sourceShadowNode);
|
|
||||||
if (source.content_.has_value() && source.content_->attachments.empty()) {
|
|
||||||
content_ = source.content_;
|
|
||||||
measuredLayouts_ = source.measuredLayouts_;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ParagraphShadowNode::shouldNewRevisionDirtyMeasurement(
|
bool ParagraphShadowNode::shouldNewRevisionDirtyMeasurement(
|
||||||
@@ -86,26 +69,8 @@ bool ParagraphShadowNode::shouldNewRevisionDirtyMeasurement(
|
|||||||
|
|
||||||
const Content& ParagraphShadowNode::getContent(
|
const Content& ParagraphShadowNode::getContent(
|
||||||
const LayoutContext& layoutContext) const {
|
const LayoutContext& layoutContext) const {
|
||||||
auto layoutDirection = YGNodeLayoutGetDirection(&yogaNode_) == YGDirectionRTL
|
|
||||||
? LayoutDirection::RightToLeft
|
|
||||||
: LayoutDirection::LeftToRight;
|
|
||||||
if (content_.has_value()) {
|
if (content_.has_value()) {
|
||||||
const auto& baseTextAttributes =
|
return content_.value();
|
||||||
content_->attributedString.getBaseTextAttributes();
|
|
||||||
// The content is built from this node's props and children, and it is
|
|
||||||
// only carried over to revisions that have neither new props nor new
|
|
||||||
// children (see the copy constructor). The only other inputs are the
|
|
||||||
// font size multiplier from the layout context and the layout direction
|
|
||||||
// Yoga resolves from the parent, and those can change without new props
|
|
||||||
// or children, so they are the two things to check here.
|
|
||||||
if (baseTextAttributes.fontSizeMultiplier ==
|
|
||||||
layoutContext.fontSizeMultiplier &&
|
|
||||||
baseTextAttributes.layoutDirection == layoutDirection) {
|
|
||||||
return content_.value();
|
|
||||||
}
|
|
||||||
// Carried over from a previous revision, but built for another context.
|
|
||||||
content_.reset();
|
|
||||||
measuredLayouts_.clear();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ensureUnsealed();
|
ensureUnsealed();
|
||||||
@@ -113,7 +78,10 @@ const Content& ParagraphShadowNode::getContent(
|
|||||||
auto textAttributes = TextAttributes::defaultTextAttributes();
|
auto textAttributes = TextAttributes::defaultTextAttributes();
|
||||||
textAttributes.fontSizeMultiplier = layoutContext.fontSizeMultiplier;
|
textAttributes.fontSizeMultiplier = layoutContext.fontSizeMultiplier;
|
||||||
textAttributes.apply(getConcreteProps().textAttributes);
|
textAttributes.apply(getConcreteProps().textAttributes);
|
||||||
textAttributes.layoutDirection = layoutDirection;
|
textAttributes.layoutDirection =
|
||||||
|
YGNodeLayoutGetDirection(&yogaNode_) == YGDirectionRTL
|
||||||
|
? LayoutDirection::RightToLeft
|
||||||
|
: LayoutDirection::LeftToRight;
|
||||||
auto attributedString = AttributedString{};
|
auto attributedString = AttributedString{};
|
||||||
auto attachments = Attachments{};
|
auto attachments = Attachments{};
|
||||||
buildAttributedString(textAttributes, *this, attributedString, attachments);
|
buildAttributedString(textAttributes, *this, attributedString, attachments);
|
||||||
@@ -236,8 +204,7 @@ void ParagraphShadowNode::updateStateIfNeeded(const Content& content) {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
MeasuredPreparedTextLayout* ParagraphShadowNode::findUsableLayout(
|
MeasuredPreparedTextLayout* ParagraphShadowNode::findUsableLayout() {
|
||||||
Float pointScaleFactor) {
|
|
||||||
MeasuredPreparedTextLayout* ret = nullptr;
|
MeasuredPreparedTextLayout* ret = nullptr;
|
||||||
|
|
||||||
if constexpr (TextLayoutManagerExtended::supportsPreparedTextLayout()) {
|
if constexpr (TextLayoutManagerExtended::supportsPreparedTextLayout()) {
|
||||||
@@ -249,8 +216,7 @@ MeasuredPreparedTextLayout* ParagraphShadowNode::findUsableLayout(
|
|||||||
// adjusted by a constraint (like min-size).
|
// adjusted by a constraint (like min-size).
|
||||||
auto expectedSize = rawContentSize();
|
auto expectedSize = rawContentSize();
|
||||||
for (auto& prevLayout : measuredLayouts_) {
|
for (auto& prevLayout : measuredLayouts_) {
|
||||||
if (prevLayout.pointScaleFactor == pointScaleFactor &&
|
if (floatEquality(
|
||||||
floatEquality(
|
|
||||||
prevLayout.measurement.size.width, expectedSize.width) &&
|
prevLayout.measurement.size.width, expectedSize.width) &&
|
||||||
floatEquality(
|
floatEquality(
|
||||||
prevLayout.measurement.size.height, expectedSize.height)) {
|
prevLayout.measurement.size.height, expectedSize.height)) {
|
||||||
@@ -279,11 +245,8 @@ Size ParagraphShadowNode::measureContent(
|
|||||||
const LayoutContext& layoutContext,
|
const LayoutContext& layoutContext,
|
||||||
const LayoutConstraints& layoutConstraints) const {
|
const LayoutConstraints& layoutConstraints) const {
|
||||||
if constexpr (TextLayoutManagerExtended::supportsPreparedTextLayout()) {
|
if constexpr (TextLayoutManagerExtended::supportsPreparedTextLayout()) {
|
||||||
// Layouts carried over from a previous revision may have been prepared
|
|
||||||
// at another pixel density, which they can't be reused for.
|
|
||||||
for (const auto& layout : measuredLayouts_) {
|
for (const auto& layout : measuredLayouts_) {
|
||||||
if (layout.layoutConstraints == layoutConstraints &&
|
if (layout.layoutConstraints == layoutConstraints) {
|
||||||
layout.pointScaleFactor == layoutContext.pointScaleFactor) {
|
|
||||||
return layout.measurement.size;
|
return layout.measurement.size;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -373,7 +336,7 @@ void ParagraphShadowNode::layout(LayoutContext layoutContext) {
|
|||||||
auto content =
|
auto content =
|
||||||
getContentWithMeasuredAttachments(layoutContext, layoutConstraints);
|
getContentWithMeasuredAttachments(layoutContext, layoutConstraints);
|
||||||
|
|
||||||
auto measuredLayout = findUsableLayout(layoutContext.pointScaleFactor);
|
auto measuredLayout = findUsableLayout();
|
||||||
|
|
||||||
if constexpr (
|
if constexpr (
|
||||||
TextLayoutManagerExtended::supportsPreparedTextLayout() &&
|
TextLayoutManagerExtended::supportsPreparedTextLayout() &&
|
||||||
@@ -390,7 +353,7 @@ void ParagraphShadowNode::layout(LayoutContext layoutContext) {
|
|||||||
// culled
|
// culled
|
||||||
if (measuredLayout == nullptr) {
|
if (measuredLayout == nullptr) {
|
||||||
measureContent(layoutContext, layoutConstraints);
|
measureContent(layoutContext, layoutConstraints);
|
||||||
measuredLayout = findUsableLayout(layoutContext.pointScaleFactor);
|
measuredLayout = findUsableLayout();
|
||||||
}
|
}
|
||||||
react_native_assert(measuredLayout);
|
react_native_assert(measuredLayout);
|
||||||
updateStateIfNeeded<ParagraphState>(content, *measuredLayout);
|
updateStateIfNeeded<ParagraphState>(content, *measuredLayout);
|
||||||
|
|||||||
+2
-3
@@ -117,10 +117,9 @@ class ParagraphShadowNode
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns any previously prepared layout, generated for measurement, which
|
* Returns any previously prepared layout, generated for measurement, which
|
||||||
* may be used, given the currently assigned layout to the ShadowNode and
|
* may be used, given the currently assigned layout to the ShadowNode
|
||||||
* the current pixel density
|
|
||||||
*/
|
*/
|
||||||
MeasuredPreparedTextLayout *findUsableLayout(Float pointScaleFactor);
|
MeasuredPreparedTextLayout *findUsableLayout();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the final measure of the content frame, before layout rounding
|
* Returns the final measure of the content frame, before layout rounding
|
||||||
|
|||||||
Reference in new issue
Block a user