Merge restoreEnterViewTransitions and restoreExitViewTransitions (#32585)

This is the exact same code in both cases. It's just general clean up.

By unifying them it becomes less confusing to reuse these helpers in the
Apply Gesture path where the naming is reversed.
This commit is contained in:
Sebastian Markbåge 2025-03-14 13:16:20 -04:00 committed by GitHub
parent 5398b71158
commit 1b6e3dd985
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 13 additions and 31 deletions

View File

@ -514,37 +514,20 @@ function restorePairedViewTransitions(parent: Fiber): void {
}
}
export function restoreEnterViewTransitions(placement: Fiber): void {
if (placement.tag === ViewTransitionComponent) {
const instance: ViewTransitionState = placement.stateNode;
export function restoreEnterOrExitViewTransitions(fiber: Fiber): void {
if (fiber.tag === ViewTransitionComponent) {
const instance: ViewTransitionState = fiber.stateNode;
instance.paired = null;
restoreViewTransitionOnHostInstances(placement.child, false);
restorePairedViewTransitions(placement);
} else if ((placement.subtreeFlags & ViewTransitionStatic) !== NoFlags) {
let child = placement.child;
restoreViewTransitionOnHostInstances(fiber.child, false);
restorePairedViewTransitions(fiber);
} else if ((fiber.subtreeFlags & ViewTransitionStatic) !== NoFlags) {
let child = fiber.child;
while (child !== null) {
restoreEnterViewTransitions(child);
restoreEnterOrExitViewTransitions(child);
child = child.sibling;
}
} else {
restorePairedViewTransitions(placement);
}
}
export function restoreExitViewTransitions(deletion: Fiber): void {
if (deletion.tag === ViewTransitionComponent) {
const instance: ViewTransitionState = deletion.stateNode;
instance.paired = null;
restoreViewTransitionOnHostInstances(deletion.child, false);
restorePairedViewTransitions(deletion);
} else if ((deletion.subtreeFlags & ViewTransitionStatic) !== NoFlags) {
let child = deletion.child;
while (child !== null) {
restoreExitViewTransitions(child);
child = child.sibling;
}
} else {
restorePairedViewTransitions(deletion);
restorePairedViewTransitions(fiber);
}
}

View File

@ -246,8 +246,7 @@ import {
commitExitViewTransitions,
commitBeforeUpdateViewTransition,
commitNestedViewTransitions,
restoreEnterViewTransitions,
restoreExitViewTransitions,
restoreEnterOrExitViewTransitions,
restoreUpdateViewTransition,
restoreNestedViewTransitions,
measureUpdateViewTransition,
@ -3228,7 +3227,7 @@ function commitPassiveMountOnFiber(
// This was a new mount. This means we could've triggered an enter animation on
// the content. Restore the view transitions if there were any assigned in the
// snapshot phase.
restoreEnterViewTransitions(finishedWork);
restoreEnterOrExitViewTransitions(finishedWork);
}
// When updating this function, also update reconnectPassiveEffects, which does
@ -3529,7 +3528,7 @@ function commitPassiveMountOnFiber(
// Content is now hidden but wasn't before. This means we could've
// triggered an exit animation on the content. Restore the view
// transitions if there were any assigned in the snapshot phase.
restoreExitViewTransitions(current);
restoreEnterOrExitViewTransitions(current);
}
if (instance._visibility & OffscreenPassiveEffectsConnected) {
// The effects are currently connected. Update them.
@ -3576,7 +3575,7 @@ function commitPassiveMountOnFiber(
// Content is now visible but wasn't before. This means we could've
// triggered an enter animation on the content. Restore the view
// transitions if there were any assigned in the snapshot phase.
restoreEnterViewTransitions(finishedWork);
restoreEnterOrExitViewTransitions(finishedWork);
}
if (instance._visibility & OffscreenPassiveEffectsConnected) {
// The effects are currently connected. Update them.