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 { useLocation } from "react-router-dom";
|
||||
import LoadingScreen from "./LoadingScreen";
|
||||
|
||||
interface PageTransitionProps {
|
||||
children: React.ReactNode;
|
||||
}
|
||||
|
||||
export default function PageTransition({ children }: PageTransitionProps) {
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
const [isVisible, setIsVisible] = useState(true);
|
||||
const [visible, setVisible] = useState(false);
|
||||
const location = useLocation();
|
||||
|
||||
useEffect(() => {
|
||||
setIsLoading(true);
|
||||
setIsVisible(false);
|
||||
|
||||
const timer = setTimeout(() => {
|
||||
setIsLoading(false);
|
||||
setIsVisible(true);
|
||||
}, 600);
|
||||
|
||||
return () => clearTimeout(timer);
|
||||
setVisible(false);
|
||||
const id = requestAnimationFrame(() => setVisible(true));
|
||||
return () => cancelAnimationFrame(id);
|
||||
}, [location.pathname]);
|
||||
|
||||
return (
|
||||
<>
|
||||
{isLoading && (
|
||||
<LoadingScreen message="Transitioning..." variant="overlay" size="md" />
|
||||
)}
|
||||
<div
|
||||
className={`transition-all duration-500 ${isVisible ? "animate-fade-in" : "opacity-0"}`}
|
||||
>
|
||||
{children}
|
||||
</div>
|
||||
</>
|
||||
<div className={`transition-opacity duration-300 ease-out transform-gpu will-change-[opacity] ${visible ? "opacity-100" : "opacity-0"}`}>
|
||||
{children}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue