Skip to content

Commit ad2f451

Browse files
javachemeta-codesync[bot]
authored andcommitted
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
1 parent 6f6fa0a commit ad2f451

2 files changed

Lines changed: 12 additions & 50 deletions

File tree

‎packages/react-native/ReactCommon/react/renderer/components/text/ParagraphShadowNode.cpp‎

Lines changed: 10 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -59,23 +59,6 @@ ParagraphShadowNode::ParagraphShadowNode(
5959
const ShadowNodeFragment& fragment)
6060
: ConcreteViewShadowNode(sourceShadowNode, fragment) {
6161
initialize();
62-
// A revision with neither new props nor new children (e.g. one Yoga cloned
63-
// because a sibling changed) renders the same content, so keep the
64-
// attributed string and the layouts measured for it instead of rebuilding
65-
// and re-measuring them. `getContent` drops both if the layout context they
66-
// were built for no longer matches.
67-
//
68-
// Content with attachments is not kept: they point at the children the
69-
// content was built from, and `layout` replaces those children with laid-out
70-
// clones, so in a later revision the pointers would outlive the nodes.
71-
if (fragment.props == nullptr && fragment.children == nullptr) {
72-
const auto& source =
73-
static_cast<const ParagraphShadowNode&>(sourceShadowNode);
74-
if (source.content_.has_value() && source.content_->attachments.empty()) {
75-
content_ = source.content_;
76-
measuredLayouts_ = source.measuredLayouts_;
77-
}
78-
}
7962
}
8063

8164
bool ParagraphShadowNode::shouldNewRevisionDirtyMeasurement(
@@ -86,34 +69,19 @@ bool ParagraphShadowNode::shouldNewRevisionDirtyMeasurement(
8669

8770
const Content& ParagraphShadowNode::getContent(
8871
const LayoutContext& layoutContext) const {
89-
auto layoutDirection = YGNodeLayoutGetDirection(&yogaNode_) == YGDirectionRTL
90-
? LayoutDirection::RightToLeft
91-
: LayoutDirection::LeftToRight;
9272
if (content_.has_value()) {
93-
const auto& baseTextAttributes =
94-
content_->attributedString.getBaseTextAttributes();
95-
// The content is built from this node's props and children, and it is
96-
// only carried over to revisions that have neither new props nor new
97-
// children (see the copy constructor). The only other inputs are the
98-
// font size multiplier from the layout context and the layout direction
99-
// Yoga resolves from the parent, and those can change without new props
100-
// or children, so they are the two things to check here.
101-
if (baseTextAttributes.fontSizeMultiplier ==
102-
layoutContext.fontSizeMultiplier &&
103-
baseTextAttributes.layoutDirection == layoutDirection) {
104-
return content_.value();
105-
}
106-
// Carried over from a previous revision, but built for another context.
107-
content_.reset();
108-
measuredLayouts_.clear();
73+
return content_.value();
10974
}
11075

11176
ensureUnsealed();
11277

11378
auto textAttributes = TextAttributes::defaultTextAttributes();
11479
textAttributes.fontSizeMultiplier = layoutContext.fontSizeMultiplier;
11580
textAttributes.apply(getConcreteProps().textAttributes);
116-
textAttributes.layoutDirection = layoutDirection;
81+
textAttributes.layoutDirection =
82+
YGNodeLayoutGetDirection(&yogaNode_) == YGDirectionRTL
83+
? LayoutDirection::RightToLeft
84+
: LayoutDirection::LeftToRight;
11785
auto attributedString = AttributedString{};
11886
auto attachments = Attachments{};
11987
buildAttributedString(textAttributes, *this, attributedString, attachments);
@@ -236,8 +204,7 @@ void ParagraphShadowNode::updateStateIfNeeded(const Content& content) {
236204
#endif
237205
}
238206

239-
MeasuredPreparedTextLayout* ParagraphShadowNode::findUsableLayout(
240-
Float pointScaleFactor) {
207+
MeasuredPreparedTextLayout* ParagraphShadowNode::findUsableLayout() {
241208
MeasuredPreparedTextLayout* ret = nullptr;
242209

243210
if constexpr (TextLayoutManagerExtended::supportsPreparedTextLayout()) {
@@ -249,8 +216,7 @@ MeasuredPreparedTextLayout* ParagraphShadowNode::findUsableLayout(
249216
// adjusted by a constraint (like min-size).
250217
auto expectedSize = rawContentSize();
251218
for (auto& prevLayout : measuredLayouts_) {
252-
if (prevLayout.pointScaleFactor == pointScaleFactor &&
253-
floatEquality(
219+
if (floatEquality(
254220
prevLayout.measurement.size.width, expectedSize.width) &&
255221
floatEquality(
256222
prevLayout.measurement.size.height, expectedSize.height)) {
@@ -279,11 +245,8 @@ Size ParagraphShadowNode::measureContent(
279245
const LayoutContext& layoutContext,
280246
const LayoutConstraints& layoutConstraints) const {
281247
if constexpr (TextLayoutManagerExtended::supportsPreparedTextLayout()) {
282-
// Layouts carried over from a previous revision may have been prepared
283-
// at another pixel density, which they can't be reused for.
284248
for (const auto& layout : measuredLayouts_) {
285-
if (layout.layoutConstraints == layoutConstraints &&
286-
layout.pointScaleFactor == layoutContext.pointScaleFactor) {
249+
if (layout.layoutConstraints == layoutConstraints) {
287250
return layout.measurement.size;
288251
}
289252
}
@@ -373,7 +336,7 @@ void ParagraphShadowNode::layout(LayoutContext layoutContext) {
373336
auto content =
374337
getContentWithMeasuredAttachments(layoutContext, layoutConstraints);
375338

376-
auto measuredLayout = findUsableLayout(layoutContext.pointScaleFactor);
339+
auto measuredLayout = findUsableLayout();
377340

378341
if constexpr (
379342
TextLayoutManagerExtended::supportsPreparedTextLayout() &&
@@ -390,7 +353,7 @@ void ParagraphShadowNode::layout(LayoutContext layoutContext) {
390353
// culled
391354
if (measuredLayout == nullptr) {
392355
measureContent(layoutContext, layoutConstraints);
393-
measuredLayout = findUsableLayout(layoutContext.pointScaleFactor);
356+
measuredLayout = findUsableLayout();
394357
}
395358
react_native_assert(measuredLayout);
396359
updateStateIfNeeded<ParagraphState>(content, *measuredLayout);

‎packages/react-native/ReactCommon/react/renderer/components/text/ParagraphShadowNode.h‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,9 @@ class ParagraphShadowNode
117117

118118
/**
119119
* Returns any previously prepared layout, generated for measurement, which
120-
* may be used, given the currently assigned layout to the ShadowNode and
121-
* the current pixel density
120+
* may be used, given the currently assigned layout to the ShadowNode
122121
*/
123-
MeasuredPreparedTextLayout *findUsableLayout(Float pointScaleFactor);
122+
MeasuredPreparedTextLayout *findUsableLayout();
124123

125124
/**
126125
* Returns the final measure of the content frame, before layout rounding

0 commit comments

Comments
 (0)