feat: add route transition

This commit is contained in:
keiko233 2023-11-11 18:32:11 +08:00
parent 01d631033f
commit 1eb34e0662
4 changed files with 48 additions and 16 deletions

View File

@ -38,6 +38,7 @@
"react-hook-form": "^7.39.5", "react-hook-form": "^7.39.5",
"react-i18next": "^12.0.0", "react-i18next": "^12.0.0",
"react-router-dom": "^6.4.3", "react-router-dom": "^6.4.3",
"react-transition-group": "^4.4.5",
"react-virtuoso": "^3.1.3", "react-virtuoso": "^3.1.3",
"recoil": "^0.7.6", "recoil": "^0.7.6",
"snarkdown": "^2.0.0", "snarkdown": "^2.0.0",

View File

@ -0,0 +1,21 @@
.page-enter {
opacity: 0;
transform: scale(0.9);
}
.page-enter-active {
opacity: 1;
transform: scale(1);
transition: opacity 300ms, transform 300ms;
}
.page-exit {
opacity: 1;
transform: scale(0);
}
.page-exit-active {
opacity: 0;
transform: scale(0.9);
transition: opacity 300ms, transform 300ms;
}

View File

@ -42,6 +42,7 @@ body {
@import "./layout.scss"; @import "./layout.scss";
@import "./page.scss"; @import "./page.scss";
@import "./anime.scss";
@media (prefers-color-scheme: dark) { @media (prefers-color-scheme: dark) {
:root { :root {

View File

@ -4,7 +4,8 @@ import relativeTime from "dayjs/plugin/relativeTime";
import { SWRConfig, mutate } from "swr"; import { SWRConfig, mutate } from "swr";
import { useEffect } from "react"; import { useEffect } from "react";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
import { Route, Routes } from "react-router-dom"; import { Route, Routes, useLocation } from "react-router-dom";
import { CSSTransition, TransitionGroup } from "react-transition-group";
import { alpha, List, Paper, ThemeProvider } from "@mui/material"; import { alpha, List, Paper, ThemeProvider } from "@mui/material";
import { listen } from "@tauri-apps/api/event"; import { listen } from "@tauri-apps/api/event";
import { appWindow } from "@tauri-apps/api/window"; import { appWindow } from "@tauri-apps/api/window";
@ -34,6 +35,8 @@ const Layout = () => {
const { verge } = useVerge(); const { verge } = useVerge();
const { theme_blur, language } = verge || {}; const { theme_blur, language } = verge || {};
const location = useLocation();
useEffect(() => { useEffect(() => {
window.addEventListener("keydown", (e) => { window.addEventListener("keydown", (e) => {
// macOS有cmd+w // macOS有cmd+w
@ -136,7 +139,12 @@ const Layout = () => {
</div> </div>
)} )}
<div className="the-content"> <TransitionGroup className="the-content">
<CSSTransition
key={location.pathname}
timeout={300}
classNames="page"
>
<Routes> <Routes>
{routers.map(({ label, link, ele: Ele }) => ( {routers.map(({ label, link, ele: Ele }) => (
<Route <Route
@ -150,7 +158,8 @@ const Layout = () => {
/> />
))} ))}
</Routes> </Routes>
</div> </CSSTransition>
</TransitionGroup>
</div> </div>
</Paper> </Paper>
</ThemeProvider> </ThemeProvider>