Skip to content

Commit

Permalink
⚡ feat(custom): 图片页添加过渡效果
Browse files Browse the repository at this point in the history
ISSUES CLOSED: #50
  • Loading branch information
master1lan committed Mar 16, 2023
1 parent cb8c358 commit a7f8152
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 17 deletions.
1 change: 1 addition & 0 deletions src/routers/photo/item/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ const DivJump = styled("div")(({ theme }) => ({
position: "absolute",
bottom: "0px",
width: "100%",

backgroundImage: `linear-gradient(180deg, rgba(0, 0, 0, 0) 0%, rgba(90, 90,90, 0.8) 100%)`,
"&:hover": {
backgroundImage: `linear-gradient(180deg, rgba(0, 0, 0, 0) 0%, rgba(0, 0,0, 0.8) 100%)`,
Expand Down
18 changes: 18 additions & 0 deletions src/routers/photo/item/loadingItem.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import Skeleton from "@mui/material/Skeleton";
import React from "react";
import { PhotoMasonryLoadingItemType } from "../masonry";
type CardType = {
data: PhotoMasonryLoadingItemType;
};
export default function PhotoLoadingItem(props: CardType) {
return (
<Skeleton
variant='rounded'
animation='wave'
{...props.data}
sx={{
width: "100% !important",
}}
/>
);
}
68 changes: 51 additions & 17 deletions src/routers/photo/masonry.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import { selectPhotoLoadingState } from "@store/loading";
import { Masonry as Masonic_masonry } from "masonic";
import { useState, useEffect } from "react";
import { useState, useEffect, useMemo } from "react";
import { useAppSelector, useAppDispatch } from "@store/hooks";

import Fade from "@mui/material/Fade";
import { changeLoading } from "@store/loading/index";
import { fetchPhotoHandler } from "./tools";
import { PhotoRouterImageCardType, PhotoRouterMasonryType } from "./phototype";
import PhotoCard from "./item";
import { useScreenSize } from "@components/proview/screenSize";
import message from "@components/message";
import styles from "./photo.module.less";
//todo props type change
export default function Masonry(props: PhotoRouterMasonryType) {
import PhotoLoadingItem from "./item/loadingItem";

const usePhotoMasonryData = (props: PhotoRouterMasonryType) => {
const [lists, setList] = useState<PhotoRouterImageCardType[]>([]);
const isLoading = useAppSelector(selectPhotoLoadingState),
dispatch = useAppDispatch(),
Expand Down Expand Up @@ -61,23 +62,56 @@ export default function Masonry(props: PhotoRouterMasonryType) {
handerChangeLoading(true);
fetchHandler(1).then(() => handerChangeLoading(false));
}, [props]);
return { lists, isLoading };
};
export type PhotoMasonryLoadingItemType = Record<"width" | "height", number>;
export default function Masonry(props: PhotoRouterMasonryType) {
const { lists, isLoading } = usePhotoMasonryData(props);
const { sm, md } = useScreenSize(),
minCount = sm ? { columnCount: 2 } : {};
const loadingLists = useMemo(
() =>
Array.from({ length: 20 }, () => ({
width: 250,
height: Math.round(Math.random() * 300 + 100),
})),
[props]
);

return (
<div className={styles["container"]}>
{isLoading || (
<Masonic_masonry
items={lists}
maxColumnCount={5}
{...minCount}
columnGutter={md ? 5 : 10}
rowGutter={md ? 5 : 10}
columnWidth={200}
render={PhotoCard}
overscanBy={Infinity}
className={styles["container"]}
/>
)}
<Fade in={!isLoading} className={`${!isLoading ? "" : "hidden"}`}>
<div>
{!isLoading && (
<Masonic_masonry
items={lists}
maxColumnCount={5}
{...minCount}
columnGutter={md ? 5 : 10}
rowGutter={md ? 5 : 10}
columnWidth={200}
render={PhotoCard}
overscanBy={Infinity}
className={styles["container"]}
/>
)}
</div>
</Fade>
<Fade in={isLoading} className={`${isLoading ? "" : "hidden"}`}>
<div>
<Masonic_masonry
items={loadingLists}
maxColumnCount={5}
{...minCount}
columnGutter={md ? 5 : 10}
rowGutter={md ? 5 : 10}
columnWidth={200}
render={PhotoLoadingItem}
overscanBy={Infinity}
className={styles["container"]}
/>
</div>
</Fade>
</div>
);
}

0 comments on commit a7f8152

Please sign in to comment.