Fix/ecommerce video 400 bug #7
@@ -6,7 +6,6 @@ interface PageTransitionProps {
|
||||
}
|
||||
|
||||
const EXIT_DURATION_MS = 180;
|
||||
const ENTER_DURATION_MS = 220;
|
||||
|
||||
const NAV_ORDER: string[] = [
|
||||
"home",
|
||||
@@ -40,7 +39,7 @@ function getNavIndex(key: string): number {
|
||||
|
||||
export default function PageTransition({ viewKey, children }: PageTransitionProps) {
|
||||
const [displayedChildren, setDisplayedChildren] = useState(children);
|
||||
const [phase, setPhase] = useState<"idle" | "exit" | "enter">("idle");
|
||||
const [phase, setPhase] = useState<"idle" | "exit">("idle");
|
||||
const [exitDirection, setExitDirection] = useState<"forward" | "backward" | "neutral">("neutral");
|
||||
const prevKeyRef = useRef(viewKey);
|
||||
const timerRef = useRef<ReturnType<typeof setTimeout>>();
|
||||
@@ -73,38 +72,15 @@ export default function PageTransition({ viewKey, children }: PageTransitionProp
|
||||
setPhase("exit");
|
||||
timerRef.current = setTimeout(() => {
|
||||
setDisplayedChildren(children);
|
||||
setPhase("enter");
|
||||
setPhase("idle");
|
||||
}, EXIT_DURATION_MS);
|
||||
return () => clearTimeout(timerRef.current);
|
||||
}, [viewKey, children]);
|
||||
|
||||
// After enter animation completes, go back to idle
|
||||
useEffect(() => {
|
||||
if (phase !== "enter") return;
|
||||
const timer = setTimeout(() => setPhase("idle"), ENTER_DURATION_MS);
|
||||
return () => clearTimeout(timer);
|
||||
}, [phase]);
|
||||
|
||||
const dirClass = exitDirection === "forward" ? " is-forward" : exitDirection === "backward" ? " is-backward" : "";
|
||||
|
||||
if (phase === "exit") {
|
||||
return (
|
||||
<div className={`page-transition-wrap page-motion--exit${dirClass}`}>
|
||||
{displayedChildren}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
if (phase === "enter") {
|
||||
return (
|
||||
<div className="page-transition-wrap page-motion--enter">
|
||||
{displayedChildren}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="page-transition-wrap">
|
||||
<div className={phase === "exit" ? `page-transition-wrap page-motion--exit${dirClass}` : "page-transition-wrap"}>
|
||||
{displayedChildren}
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -53,24 +53,4 @@
|
||||
opacity: 0;
|
||||
transform: translateX(16px);
|
||||
}
|
||||
}
|
||||
|
||||
/* Enter: explicit wrapper entrance animation overrides child page-motion */
|
||||
.page-motion--enter {
|
||||
animation: page-enter-fade 220ms ease both;
|
||||
}
|
||||
|
||||
.page-motion--enter .page-motion {
|
||||
animation: none !important;
|
||||
}
|
||||
|
||||
@keyframes page-enter-fade {
|
||||
from {
|
||||
opacity: 0;
|
||||
transform: translateY(6px);
|
||||
}
|
||||
to {
|
||||
opacity: 1;
|
||||
transform: translateY(0);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user