From 57fcf6c26842d584da7bbc5fd6ceb1f162bbfc5d Mon Sep 17 00:00:00 2001 From: Joshua Gross Date: Fri, 19 Jun 2020 11:11:08 -0700 Subject: [PATCH] LayoutAnimations: when delaying a REMOVE operation, insert operation indices on the same level must also be adjusted Summary: This will prevent views from becoming out-of-order as view removals are delayed and there are inserts at the same level. There is at least one additional issue that crops up if many animations are queued up at the same time, that will be resolved separately. Changelog: [Internal] Reviewed By: sammy-SC Differential Revision: D22130185 fbshipit-source-id: d8041c6afdcd729939dd392c9e2c23fe8ec1b706 --- .../animations/LayoutAnimationKeyFrameManager.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/ReactCommon/fabric/animations/LayoutAnimationKeyFrameManager.cpp b/ReactCommon/fabric/animations/LayoutAnimationKeyFrameManager.cpp index d73c10363b..a4aa06e82b 100644 --- a/ReactCommon/fabric/animations/LayoutAnimationKeyFrameManager.cpp +++ b/ReactCommon/fabric/animations/LayoutAnimationKeyFrameManager.cpp @@ -716,14 +716,23 @@ LayoutAnimationKeyFrameManager::pullTransaction( // instruction will be delayed and therefore may execute outside of // otherwise-expected order, other views may be inserted before the // Remove is executed, requiring index adjustment. + // To be clear: when executed synchronously, REMOVE operations + // always come before INSERT operations (at the same level of the + // tree hierarchy). { int adjustedIndex = mutation.index; - for (const auto &otherMutation : mutations) { + for (auto &otherMutation : mutations) { if (otherMutation.type == ShadowViewMutation::Type::Insert && otherMutation.parentShadowView.tag == parentTag) { if (otherMutation.index <= adjustedIndex && !mutatedViewIsVirtual(otherMutation)) { adjustedIndex++; + } else { + // If we are delaying this remove instruction, conversely, + // we must adjust upward the insertion index of any INSERT + // instructions if the View is insert *after* this view in + // the hierarchy. + otherMutation.index++; } } }