From ca51dc6288eb8c8df197239cd53dff649da4e50d Mon Sep 17 00:00:00 2001 From: Joshua Gross Date: Tue, 29 Sep 2020 16:35:44 -0700 Subject: [PATCH] Fix mutation sorting function Summary: The sorting function currently forms a partial ordering, not a total ordering. This can cause problems with certain sequences of immediate or conflicting mutations, leading to UI corruption or crashes. Changelog: [Internal] Reviewed By: shergin Differential Revision: D24002668 fbshipit-source-id: edc9b4c1e3104897cb0c5fd6da563ec43d800494 --- .../LayoutAnimationKeyFrameManager.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/ReactCommon/react/renderer/animations/LayoutAnimationKeyFrameManager.h b/ReactCommon/react/renderer/animations/LayoutAnimationKeyFrameManager.h index e6aba6e3c07..891d25d46d1 100644 --- a/ReactCommon/react/renderer/animations/LayoutAnimationKeyFrameManager.h +++ b/ReactCommon/react/renderer/animations/LayoutAnimationKeyFrameManager.h @@ -308,6 +308,14 @@ static inline bool shouldFirstComeBeforeSecondMutation( return true; } + // Update comes last, before deletes + if (rhs.type == ShadowViewMutation::Type::Update) { + return true; + } + if (lhs.type == ShadowViewMutation::Type::Update) { + return false; + } + // Remove comes before insert if (lhs.type == ShadowViewMutation::Type::Remove && rhs.type == ShadowViewMutation::Type::Insert) { @@ -317,6 +325,16 @@ static inline bool shouldFirstComeBeforeSecondMutation( lhs.type == ShadowViewMutation::Type::Insert) { return false; } + + // Create comes before insert + if (lhs.type == ShadowViewMutation::Type::Create && + rhs.type == ShadowViewMutation::Type::Insert) { + return true; + } + if (rhs.type == ShadowViewMutation::Type::Create && + lhs.type == ShadowViewMutation::Type::Insert) { + return false; + } } else { // Make sure that removes on the same level are sorted - highest indices // must come first.