Skip to content

Commit 5f55c0d

Browse files
hryhoriiK97claude
andcommitted
Share the slicing code between replaced leaves and unchanged children
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent c183a8f commit 5f55c0d

1 file changed

Lines changed: 18 additions & 37 deletions

File tree

‎packages/react-native/ReactCommon/react/renderer/mounting/internal/sliceChildShadowNodeViewPairs.cpp‎

Lines changed: 18 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -264,42 +264,18 @@ bool sliceChangedChildShadowNodeViewPairsRecursively(
264264
continue;
265265
}
266266

267-
if (oldChildShadowNode.getTag() != newChildShadowNode.getTag() ||
267+
// A child whose tag or order index changed can still be listed if it is a
268+
// leaf that doesn't form a view, like the raw text of a `Text` whose
269+
// string changed: it has no mount index, so it doesn't shift the views
270+
// around it, and both lists are sorted by order index at the end.
271+
bool isReplaced =
272+
oldChildShadowNode.getTag() != newChildShadowNode.getTag() ||
268273
oldChildShadowNode.getOrderIndex() !=
269-
newChildShadowNode.getOrderIndex()) {
270-
// A replaced leaf that doesn't form a view (like the raw text of a
271-
// `Text` whose string changed) has no mount index, so both nodes can be
272-
// listed as they are without shifting the views around them.
273-
if (!oldChildShadowNode.getChildren().empty() ||
274-
!newChildShadowNode.getChildren().empty()) {
275-
return false;
276-
}
277-
auto oldLeafSlice = sliceChild(
278-
oldShadowNode,
279-
oldChildShadowNode,
280-
ShadowView(oldChildShadowNode),
281-
oldLayoutOffset);
282-
auto newLeafSlice = sliceChild(
283-
newShadowNode,
284-
newChildShadowNode,
285-
ShadowView(newChildShadowNode),
286-
newLayoutOffset);
287-
if (oldLeafSlice.isConcreteView || newLeafSlice.isConcreteView) {
288-
return false;
289-
}
290-
addChildSlice(
291-
oldPairList,
292-
oldStartOfStaticIndex,
293-
scope,
294-
oldLeafSlice,
295-
oldChildShadowNode);
296-
addChildSlice(
297-
newPairList,
298-
newStartOfStaticIndex,
299-
scope,
300-
newLeafSlice,
301-
newChildShadowNode);
302-
continue;
274+
newChildShadowNode.getOrderIndex();
275+
if (isReplaced &&
276+
(!oldChildShadowNode.getChildren().empty() ||
277+
!newChildShadowNode.getChildren().empty())) {
278+
return false;
303279
}
304280

305281
auto oldChildSlice = sliceChild(
@@ -314,7 +290,12 @@ bool sliceChangedChildShadowNodeViewPairsRecursively(
314290
newLayoutOffset);
315291
bool isStatic = newChildSlice.shadowView.layoutMetrics.positionType ==
316292
PositionType::Static;
317-
if (oldChildSlice.isConcreteView != newChildSlice.isConcreteView ||
293+
if (isReplaced) {
294+
if (oldChildSlice.isConcreteView || newChildSlice.isConcreteView) {
295+
return false;
296+
}
297+
} else if (
298+
oldChildSlice.isConcreteView != newChildSlice.isConcreteView ||
318299
oldChildSlice.areChildrenFlattened !=
319300
newChildSlice.areChildrenFlattened ||
320301
(oldChildSlice.shadowView.layoutMetrics.positionType ==
@@ -335,7 +316,7 @@ bool sliceChangedChildShadowNodeViewPairsRecursively(
335316
newChildSlice,
336317
newChildShadowNode);
337318

338-
if (!newChildSlice.areChildrenFlattened) {
319+
if (isReplaced || !newChildSlice.areChildrenFlattened) {
339320
continue;
340321
}
341322
if (isStatic) {

0 commit comments

Comments
 (0)