Skip to content

Commit

Permalink
[Shared Element Transition] Fix exiting animations on Android (softwa…
Browse files Browse the repository at this point in the history
…re-mansion#4038)

## Summary

I shouldn't clear the layout animation config when the shared element
transition doesn't start. Without this check, the exiting layout
animation couldn't start because LayoutAnimationManager doesn't contain
the view config.

## Test plan

Run exiting layout animation on Android.
  • Loading branch information
piaskowyk authored and fluiddot committed Jun 5, 2023
1 parent bff033b commit 492a3b1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,18 @@ protected View getTransitioningView(int tag) {
}

protected void viewsDidLayout() {
startSharedTransitionForViews(mAddedSharedViews, true);
tryStartSharedTransitionForViews(mAddedSharedViews, true);
mAddedSharedViews.clear();
}

protected void onViewsRemoval(int[] tagsToDelete) {
if (tagsToDelete != null) {
visitTreeForTags(tagsToDelete, new SnapshotTreeVisitor());

startSharedTransitionForViews(mRemovedSharedViews, false);
boolean animationStarted = tryStartSharedTransitionForViews(mRemovedSharedViews, false);
if (!animationStarted) {
return;
}
ConfigCleanerTreeVisitor configCleanerTreeVisitor = new ConfigCleanerTreeVisitor();
for (View removedSharedView : mRemovedSharedViews) {
visitTree(removedSharedView, configCleanerTreeVisitor);
Expand Down Expand Up @@ -85,19 +88,21 @@ protected void setNativeMethods(NativeMethodsHolder nativeMethods) {
mNativeMethodsHolder = nativeMethods;
}

private void startSharedTransitionForViews(List<View> sharedViews, boolean withNewElements) {
private boolean tryStartSharedTransitionForViews(
List<View> sharedViews, boolean withNewElements) {
if (sharedViews.isEmpty()) {
return;
return false;
}
sortViewsByTags(sharedViews);
List<SharedElement> sharedElements =
getSharedElementsForCurrentTransition(sharedViews, withNewElements);
if (sharedElements.isEmpty()) {
return;
return false;
}
setupTransitionContainer();
reparentSharedViewsForCurrentTransition(sharedElements);
startSharedTransition(sharedElements);
return true;
}

private void sortViewsByTags(List<View> views) {
Expand Down
4 changes: 2 additions & 2 deletions ios/LayoutReanimation/REASharedTransitionManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -360,8 +360,8 @@ - (void)runSharedTransitionForSharedViewsOnScreen:(UIView *)screen
}
return false;
});
BOOL startedAnimation = [self configureAndStartSharedTransitionForViews:removedViews];
if (startedAnimation) {
BOOL animationStarted = [self configureAndStartSharedTransitionForViews:removedViews];
if (animationStarted) {
for (UIView *view in removedViews) {
[_animationManager clearAnimationConfigForTag:view.reactTag];
}
Expand Down

0 comments on commit 492a3b1

Please sign in to comment.