Simplify PageTransition to fast fade without overlay
cgen-090757e34c764632ac3dfca36ace0c37
This commit is contained in:
parent
a285036b20
commit
8533b20675
1 changed files with 7 additions and 22 deletions
|
|
@ -1,38 +1,23 @@
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import { useLocation } from "react-router-dom";
|
import { useLocation } from "react-router-dom";
|
||||||
import LoadingScreen from "./LoadingScreen";
|
|
||||||
|
|
||||||
interface PageTransitionProps {
|
interface PageTransitionProps {
|
||||||
children: React.ReactNode;
|
children: React.ReactNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function PageTransition({ children }: PageTransitionProps) {
|
export default function PageTransition({ children }: PageTransitionProps) {
|
||||||
const [isLoading, setIsLoading] = useState(false);
|
const [visible, setVisible] = useState(false);
|
||||||
const [isVisible, setIsVisible] = useState(true);
|
|
||||||
const location = useLocation();
|
const location = useLocation();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setIsLoading(true);
|
setVisible(false);
|
||||||
setIsVisible(false);
|
const id = requestAnimationFrame(() => setVisible(true));
|
||||||
|
return () => cancelAnimationFrame(id);
|
||||||
const timer = setTimeout(() => {
|
|
||||||
setIsLoading(false);
|
|
||||||
setIsVisible(true);
|
|
||||||
}, 600);
|
|
||||||
|
|
||||||
return () => clearTimeout(timer);
|
|
||||||
}, [location.pathname]);
|
}, [location.pathname]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<div className={`transition-opacity duration-300 ease-out transform-gpu will-change-[opacity] ${visible ? "opacity-100" : "opacity-0"}`}>
|
||||||
{isLoading && (
|
{children}
|
||||||
<LoadingScreen message="Transitioning..." variant="overlay" size="md" />
|
</div>
|
||||||
)}
|
|
||||||
<div
|
|
||||||
className={`transition-all duration-500 ${isVisible ? "animate-fade-in" : "opacity-0"}`}
|
|
||||||
>
|
|
||||||
{children}
|
|
||||||
</div>
|
|
||||||
</>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue