Skip to content

Commit

Permalink
LayoutAnimations: don't animate root ShadowNode mutations
Browse files Browse the repository at this point in the history
Summary:
Root nodes doesn't have a ComponentDescriptor that can be looked up via this mechanism, and we probably shouldn't be animating Root nodes anyway (?). This is a debug-only assert but could be causing issues in production.

The fix is simple - just don't animate any changes to a root node.

Changelog: [Internal]

Reviewed By: Nick177

Differential Revision: D28856396

fbshipit-source-id: 43fa0aa723b03b031fee22e0563eb63cc86239b3
  • Loading branch information
JoshuaGross authored and Setito committed Jul 17, 2021
1 parent 91f8c42 commit 1557781
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
Expand Up @@ -913,6 +913,13 @@ LayoutAnimationKeyFrameManager::pullTransaction(
bool haveComponentDescriptor =
hasComponentDescriptorForShadowView(baselineShadowView);

// Immediately execute any mutations on a root node
if (baselineShadowView.traits.check(
ShadowNodeTraits::Trait::RootNodeKind)) {
immediateMutations.push_back(mutation);
continue;
}

better::optional<ShadowViewMutation> executeMutationImmediately{};

bool isRemoveReinserted =
Expand Down Expand Up @@ -1709,6 +1716,8 @@ ShadowView LayoutAnimationKeyFrameManager::createInterpolatedShadowView(
react_native_assert(startingView.tag > 0);
react_native_assert(finalView.tag > 0);
if (!hasComponentDescriptorForShadowView(startingView)) {
LOG(ERROR) << "No ComponentDescriptor for ShadowView being animated: ["
<< startingView.tag << "]";
react_native_assert(false);
return finalView;
}
Expand Down
Expand Up @@ -73,8 +73,6 @@ static void testShadowNodeTreeLifeCycleLayoutAnimations(
componentDescriptorParameters);
providerRegistry->add(
concreteComponentDescriptorProvider<ViewComponentDescriptor>());
providerRegistry->add(
concreteComponentDescriptorProvider<RootComponentDescriptor>());

// Create Animation Driver
auto animationDriver =
Expand Down Expand Up @@ -162,6 +160,13 @@ static void testShadowNodeTreeLifeCycleLayoutAnimations(
continue;
}

// If we only mutated the root... also don't bother
if (originalMutations.size() == 1 &&
(originalMutations[0].oldChildShadowView.tag == 1 ||
originalMutations[0].newChildShadowView.tag == 1)) {
continue;
}

// Configure animation
animationDriver->uiManagerDidConfigureNextLayoutAnimation(
{surfaceId,
Expand Down

0 comments on commit 1557781

Please sign in to comment.