Skip to content

Commit d8fe0d2

Browse files
sammy-SCfacebook-github-bot
authored andcommitted
simplify parent-child flattening-unflattening (#50893)
Summary: Pull Request resolved: #50893 changelog: [internal] In the two branches changed by this diff, it is unnecessary to check `reparentMode` because `reparentMode` and `childReparentMode` will always mismatch. When `childReparentMode` is unflatten, `reparentMode` will be flatten and vice versa. This is guaranteed by a `if else` statement above: https://github.com/facebook/react-native/blob/main/packages/react-native/ReactCommon/react/renderer/mounting/Differentiator.cpp#L674 This slightly simplifies code and lowers the burden on the reader. Reviewed By: javache, rubennorte Differential Revision: D73571160 fbshipit-source-id: 8623d991f7b063f70c95720ca0d3b63318dfc08b
1 parent 94fed5f commit d8fe0d2

File tree

1 file changed

+13
-24
lines changed

1 file changed

+13
-24
lines changed

packages/react-native/ReactCommon/react/renderer/mounting/Differentiator.cpp

Lines changed: 13 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -699,9 +699,10 @@ static void calculateShadowViewMutationsFlattener(
699699
}
700700
}
701701

702-
// Unflatten parent, flatten child
703702
if (childReparentMode == ReparentMode::Flatten) {
704-
auto parentTagForUpdateWhenUnflattened =
703+
// Unflatten parent, flatten child
704+
react_native_assert(reparentMode == ReparentMode::Unflatten);
705+
auto fixedParentTagForUpdate =
705706
ReactNativeFeatureFlags::
706707
enableFixForParentTagDuringReparenting()
707708
? newTreeNodePair.shadowView.tag
@@ -715,22 +716,18 @@ static void calculateShadowViewMutationsFlattener(
715716
scope,
716717
ReparentMode::Flatten,
717718
mutationContainer,
718-
(reparentMode == ReparentMode::Flatten
719-
? parentTag
720-
: newTreeNodePair.shadowView.tag),
719+
newTreeNodePair.shadowView.tag,
721720
unvisitedRecursiveChildPairs,
722721
oldTreeNodePair,
723-
(reparentMode == ReparentMode::Flatten
724-
? oldTreeNodePair.shadowView.tag
725-
: parentTagForUpdateWhenUnflattened),
722+
fixedParentTagForUpdate,
726723
subVisitedNewMap,
727724
subVisitedOldMap,
728-
cullingContext.adjustCullingContextIfNeeded(oldTreeNodePair));
729-
}
730-
// Flatten parent, unflatten child
731-
else {
725+
adjustedNewCullingContext);
726+
} else {
727+
// Flatten parent, unflatten child
728+
react_native_assert(reparentMode == ReparentMode::Flatten);
732729
// Unflatten old list into new tree
733-
auto parentTagForUpdateWhenFlattened =
730+
auto fixedParentTagForUpdate =
734731
ReactNativeFeatureFlags::
735732
enableFixForParentTagDuringReparenting()
736733
? parentTagForUpdate
@@ -739,21 +736,13 @@ static void calculateShadowViewMutationsFlattener(
739736
scope,
740737
/* reparentMode */ ReparentMode::Unflatten,
741738
mutationContainer,
742-
/* parentTag */
743-
(reparentMode == ReparentMode::Flatten
744-
? parentTag
745-
: newTreeNodePair.shadowView.tag),
739+
parentTag,
746740
/* unvisitedOtherNodes */ unvisitedRecursiveChildPairs,
747741
/* node */ newTreeNodePair,
748-
/* parentTagForUpdate */
749-
(reparentMode == ReparentMode::Flatten
750-
? parentTagForUpdateWhenFlattened
751-
: parentTag),
742+
/* parentTagForUpdate */ fixedParentTagForUpdate,
752743
/* parentSubVisitedOtherNewNodes */ subVisitedNewMap,
753744
/* parentSubVisitedOtherOldNodes */ subVisitedOldMap,
754-
reparentMode == ReparentMode::Flatten
755-
? adjustedOldCullingContext
756-
: adjustedNewCullingContext);
745+
/* cullingContext */ adjustedOldCullingContext);
757746

758747
// If old nodes were not visited, we know that we can delete them
759748
// now. They will be removed from the hierarchy by the outermost

0 commit comments

Comments
 (0)