diff --git a/apps/desktop/layer/renderer/src/components/ui/modal/stacked/custom-modal.tsx b/apps/desktop/layer/renderer/src/components/ui/modal/stacked/custom-modal.tsx index a403365bc..52024644e 100644 --- a/apps/desktop/layer/renderer/src/components/ui/modal/stacked/custom-modal.tsx +++ b/apps/desktop/layer/renderer/src/components/ui/modal/stacked/custom-modal.tsx @@ -28,6 +28,11 @@ export const SlideUpModal: ModalTemplateType = (props) => { y: winHeight, opacity: 0, }} + onAnimationComplete={(definition) => { + if (definition === "exit") { + dismiss() + } + }} className={cn( "bg-theme-background relative flex flex-col items-center overflow-hidden rounded-xl border p-8 pb-0", "aspect-[7/9] w-[600px] max-w-full shadow lg:max-h-[calc(100vh-10rem)]", @@ -63,6 +68,7 @@ const modalVariant = { opacity: 0, }, } + export const DrawerModalLayout: FC = ({ children }) => { const { dismiss } = useCurrentModal() const controller = useAnimationControls() @@ -84,6 +90,11 @@ export const DrawerModalLayout: FC = ({ children }) => { tension: 100, friction: 1, }} + onAnimationComplete={(definition) => { + if (definition === "exit") { + dismiss() + } + }} exit="exit" layout="size" className={cn( diff --git a/apps/desktop/layer/renderer/src/components/ui/modal/stacked/modal.tsx b/apps/desktop/layer/renderer/src/components/ui/modal/stacked/modal.tsx index f18dc3e6f..2c4077cfd 100644 --- a/apps/desktop/layer/renderer/src/components/ui/modal/stacked/modal.tsx +++ b/apps/desktop/layer/renderer/src/components/ui/modal/stacked/modal.tsx @@ -3,7 +3,7 @@ import { EllipsisHorizontalTextWithTooltip } from "@follow/components/ui/typogra import { ZIndexProvider } from "@follow/components/ui/z-index/index.js" import { useRefValue } from "@follow/hooks" import { ELECTRON_BUILD } from "@follow/shared/constants" -import { nextFrame, preventDefault, stopPropagation } from "@follow/utils/dom" +import { preventDefault, stopPropagation } from "@follow/utils/dom" import { cn, getOS } from "@follow/utils/utils" import * as Dialog from "@radix-ui/react-dialog" import { produce } from "immer" @@ -100,9 +100,7 @@ export const ModalInternal = memo( setStack((p) => p.filter((modal) => modal.id !== item.id)) }) } else { - nextFrame(() => { - setStack((p) => p.filter((modal) => modal.id !== item.id)) - }) + setStack((p) => p.filter((modal) => modal.id !== item.id)) } onPropsClose?.(false) }) diff --git a/apps/desktop/layer/renderer/src/modules/discover/recommendations-card.tsx b/apps/desktop/layer/renderer/src/modules/discover/recommendations-card.tsx index 72194dc8c..8361b4074 100644 --- a/apps/desktop/layer/renderer/src/modules/discover/recommendations-card.tsx +++ b/apps/desktop/layer/renderer/src/modules/discover/recommendations-card.tsx @@ -1,4 +1,5 @@ import { Card, CardContent, CardHeader, CardTitle } from "@follow/components/ui/card/index.jsx" +import { SiteIcon } from "@follow/components/ui/icon/SiteIcon.js" import { RSSHubCategories } from "@follow/constants" import { getHighestWeightColor } from "@follow/utils/color" import { clsx, cn, getUrlIcon } from "@follow/utils/utils" @@ -54,7 +55,7 @@ export const RecommendationCard: FC = memo( - + { - flushSync(() => { - setCategory(value) - }) - rsshubPopular.refetch() - } + const handleCategoryChange = useCallback( + (value: DiscoverCategories) => { + flushSync(() => { + setCategory(value) + }) + rsshubPopular.refetch() + }, + [rsshubPopular], + ) - const handleLangChange = (value: string) => { - flushSync(() => { - setSelectedLang(value as Language) - }) - rsshubPopular.refetch() - } + const handleLangChange = useCallback( + (value: string) => { + flushSync(() => { + setSelectedLang(value as Language) + }) + rsshubPopular.refetch() + }, + [rsshubPopular], + ) const handleShowCategoryContent = (selectedCategory: DiscoverCategories) => { present({ @@ -222,6 +228,16 @@ const RecommendationDrawerContent = ({ const { dismiss } = useCurrentModal() + // Delay the masonry rendering to avoid layout shift + const [ready, setReady] = useState(false) + const [masonryReady, setMasonryReady] = useState(false) + + useEffect(() => { + nextFrame(() => { + setReady(true) + }) + }, []) + return (

@@ -236,27 +252,34 @@ const RecommendationDrawerContent = ({ > - +
{filteredItems.length > 0 ? ( - - { - if (!itemData) return null - return ( - - ) - }} - /> + + {ready && ( + { + setTimeout(() => { + setMasonryReady(true) + }, 36) + }} + columnCount={isMobile() ? 1 : 2} + overscanBy={2} + render={({ data: itemData }) => { + if (!itemData) return null + return ( + + ) + }} + /> + )} ) : (
diff --git a/packages/internal/components/src/ui/icon/SiteIcon.tsx b/packages/internal/components/src/ui/icon/SiteIcon.tsx new file mode 100644 index 000000000..09175e12d --- /dev/null +++ b/packages/internal/components/src/ui/icon/SiteIcon.tsx @@ -0,0 +1,53 @@ +import { getFeedIconSrc } from "@follow/components/utils/icon" +import { cn } from "@follow/utils/utils" +import { m, useAnimationControls } from "motion/react" +import { useRef } from "react" + +import { PlatformIcon } from "../platform-icon" + +interface SiteIconProps { + siteUrl: string + className?: string + size?: number + fadeIn?: boolean +} +export const SiteIcon = ({ siteUrl, className, size = 20, fadeIn = true }: SiteIconProps) => { + const [src] = getFeedIconSrc({ + siteUrl, + }) + + const sizeStyle = { + width: size, + height: size, + } + + const isIconLoaded = useRef(false) + const fadeInVariant = { + opacity: [0, 1], + transition: { + duration: 0.2, + }, + } + + const animateControl = useAnimationControls() + return ( + + { + if (isIconLoaded.current) { + return + } + if (!fadeIn) { + isIconLoaded.current = true + return + } + isIconLoaded.current = true + animateControl.start(fadeInVariant) + }} + /> + + ) +}