fix: remove unused variables and clean up PageTransition component

This commit is contained in:
LTbinglingfeng
2026-01-31 12:40:41 +08:00
parent 3d33958d9e
commit b4eb2d790c

View File

@@ -95,6 +95,19 @@ export function PageTransition({
? getTransitionVariant(currentLayerPathname ?? '', location.pathname) ? getTransitionVariant(currentLayerPathname ?? '', location.pathname)
: 'vertical'; : 'vertical';
const shouldSkipExitLayer = (() => {
if (transitionVariantRef.current !== 'ios' || nextDirection !== 'backward') return false;
const normalizeSegments = (pathname: string) =>
pathname
.split('/')
.filter(Boolean)
.filter((segment) => segment.length > 0);
const fromSegments = normalizeSegments(currentLayerPathname ?? '');
const toSegments = normalizeSegments(location.pathname);
if (!fromSegments.length || !toSegments.length) return false;
return fromSegments[0] === toSegments[0] && toSegments.length === 1;
})();
setLayers((prev) => { setLayers((prev) => {
const variant = transitionVariantRef.current; const variant = transitionVariantRef.current;
const direction = transitionDirectionRef.current; const direction = transitionDirectionRef.current;
@@ -135,13 +148,22 @@ export function PageTransition({
}; };
}); });
const exitingLayer: Layer = { ...previousCurrent, status: 'exiting' }; if (shouldSkipExitLayer) {
nextLayersRef.current = targetStack;
return targetStack;
}
const exitingLayer: Layer = { ...previousCurrent, status: 'exiting' };
nextLayersRef.current = targetStack; nextLayersRef.current = targetStack;
return [...targetStack, exitingLayer]; return [...targetStack, exitingLayer];
} }
} }
if (shouldSkipExitLayer) {
nextLayersRef.current = [nextCurrent];
return [nextCurrent];
}
const exitingLayer: Layer = { ...previousCurrent, status: 'exiting' }; const exitingLayer: Layer = { ...previousCurrent, status: 'exiting' };
nextLayersRef.current = [nextCurrent]; nextLayersRef.current = [nextCurrent];