From ec6bc963a722af603128a739bb786daf0ccc1ebe Mon Sep 17 00:00:00 2001 From: Innei Date: Wed, 23 Apr 2025 15:45:18 +0800 Subject: [PATCH] refactor: migrate spring constants to centralized module - Removed the spring.ts file and replaced direct imports with centralized Spring presets in various components. - Updated transition properties in multiple files to utilize the new Spring module for consistency and maintainability. Signed-off-by: Innei --- .../src/components/ui/constants/spring.ts | 101 ---------------- .../src/components/ui/media/VideoPlayer.tsx | 6 +- .../src/components/ui/media/preview-media.tsx | 4 +- .../components/ui/modal/stacked/constants.ts | 5 +- .../src/components/ux/transition/icon.tsx | 9 +- .../src/modules/auth/LoginModalContent.tsx | 12 +- .../src/renderer/src/modules/boost/modal.tsx | 8 +- .../src/modules/boost/radio-cards.tsx | 5 +- .../renderer/src/modules/discover/form.tsx | 4 +- .../components/SourceContentView.tsx | 6 +- .../src/renderer/src/modules/panel/cmdf.tsx | 4 +- .../src/modules/player/corner-player.tsx | 4 +- .../update-notice/UpdateNotice.mobile.tsx | 4 +- .../modules/update-notice/UpdateNotice.tsx | 4 +- packages/components/package.json | 1 + packages/components/src/constants/spring.ts | 111 ++++++++++++++++++ 16 files changed, 153 insertions(+), 135 deletions(-) delete mode 100644 apps/desktop/src/renderer/src/components/ui/constants/spring.ts create mode 100644 packages/components/src/constants/spring.ts diff --git a/apps/desktop/src/renderer/src/components/ui/constants/spring.ts b/apps/desktop/src/renderer/src/components/ui/constants/spring.ts deleted file mode 100644 index 7f921c604..000000000 --- a/apps/desktop/src/renderer/src/components/ui/constants/spring.ts +++ /dev/null @@ -1,101 +0,0 @@ -import type { Spring } from "motion/react" - -export const reboundPreset: Spring = { - type: "spring", - bounce: 10, - stiffness: 140, - damping: 8, -} - -export const microDampingPreset: Spring = { - type: "spring", - damping: 24, -} - -export const microReboundPreset: Spring = { - type: "spring", - stiffness: 300, - damping: 20, -} - -export const softSpringPreset: Spring = { - duration: 0.35, - type: "spring", - stiffness: 120, - damping: 20, -} - -export const softBouncePreset: Spring = { - type: "spring", - damping: 10, - stiffness: 100, -} - -/** - * A smooth spring with a predefined duration and no bounce. - */ -export const smoothPreset: Spring = { - type: "spring", - duration: 0.5, - bounce: 0, -} - -/** - * A smooth spring with a predefined duration and no bounce that can be tuned. - * - * @param duration The perceptual duration, which defines the pace of the spring. - * @param extraBounce How much additional bounce should be added to the base bounce of 0. - */ -export function smooth(duration = 0.5, extraBounce = 0): Spring { - return { - type: "spring", - duration, - bounce: extraBounce, - } -} - -/** - * A spring with a predefined duration and small amount of bounce that feels more snappy. - */ -export const snappyPreset: Spring = { - type: "spring", - duration: 0.5, - bounce: 0.15, -} - -/** - * A spring with a predefined duration and small amount of bounce that feels more snappy and can be tuned. - * - * @param duration The perceptual duration, which defines the pace of the spring. - * @param extraBounce How much additional bounciness should be added to the base bounce of 0.15. - */ -export function snappy(duration = 0.5, extraBounce = 0): Spring { - return { - type: "spring", - duration, - bounce: 0.15 + extraBounce, - } -} - -/** - * A spring with a predefined duration and higher amount of bounce. - */ -export const bouncyPreset: Spring = { - type: "spring", - duration: 0.5, - bounce: 0.3, -} - -/** - * A spring with a predefined duration and higher amount of bounce that can be tuned. - * - * @param duration The perceptual duration, which defines the pace of the spring. - * @param extraBounce How much additional bounce should be added to the base bounce of 0.3. - */ -export function bouncy(duration = 0.5, extraBounce = 0): Spring { - return { - type: "spring", - duration, - bounce: 0.3 + extraBounce, - } -} diff --git a/apps/desktop/src/renderer/src/components/ui/media/VideoPlayer.tsx b/apps/desktop/src/renderer/src/components/ui/media/VideoPlayer.tsx index 37a8b1b62..86b453acf 100644 --- a/apps/desktop/src/renderer/src/components/ui/media/VideoPlayer.tsx +++ b/apps/desktop/src/renderer/src/components/ui/media/VideoPlayer.tsx @@ -1,4 +1,5 @@ import { Focusable } from "@follow/components/common/Focusable.js" +import { Spring } from "@follow/components/constants/spring.js" import { ActionButton, MotionButtonBase } from "@follow/components/ui/button/index.js" import type { HTMLMediaState } from "@follow/hooks" import { useRefValue, useVideo } from "@follow/hooks" @@ -25,7 +26,6 @@ import { useEventCallback } from "usehooks-ts" import { AudioPlayer } from "~/atoms/player" import { IconScaleTransition } from "~/components/ux/transition/icon" -import { softSpringPreset } from "../constants/spring" import { VolumeSlider } from "./VolumeSlider" type VideoPlayerProps = { @@ -63,8 +63,8 @@ export const VideoPlayer = forwardRef( const isPlayer = variant === "player" const [clickToStatus, setClickToStatus] = useState(null as "play" | "pause" | null) - const scaleValue = useSpring(1, softSpringPreset) - const opacityValue = useSpring(0, softSpringPreset) + const scaleValue = useSpring(1, Spring.presets.softSpring) + const opacityValue = useSpring(0, Spring.presets.softSpring) const handleClick = useEventCallback((e?: any) => { if (!isPlayer) return e?.stopPropagation() diff --git a/apps/desktop/src/renderer/src/components/ui/media/preview-media.tsx b/apps/desktop/src/renderer/src/components/ui/media/preview-media.tsx index dec76953d..394f16126 100644 --- a/apps/desktop/src/renderer/src/components/ui/media/preview-media.tsx +++ b/apps/desktop/src/renderer/src/components/ui/media/preview-media.tsx @@ -1,3 +1,4 @@ +import { Spring } from "@follow/components/constants/spring.js" import { ActionButton, MotionButtonBase } from "@follow/components/ui/button/index.js" import { RootPortal } from "@follow/components/ui/portal/index.js" import { useMeasure } from "@follow/hooks" @@ -19,7 +20,6 @@ import { COPY_MAP } from "~/constants" import { tipcClient } from "~/lib/client" import { replaceImgUrlIfNeed } from "~/lib/img-proxy" -import { microReboundPreset } from "../constants/spring" import { FixedModalCloseButton } from "../modal/components/close" import { useCurrentModal } from "../modal/stacked/hooks" import { VideoPlayer } from "./VideoPlayer" @@ -81,7 +81,7 @@ const Wrapper: Component<{ initial={{ scale: 0.94, opacity: 0 }} animate={{ scale: 1, opacity: 1 }} exit={{ scale: 0.94, opacity: 0 }} - transition={microReboundPreset} + transition={Spring.presets.microRebound} >
, diff --git a/apps/desktop/src/renderer/src/modules/auth/LoginModalContent.tsx b/apps/desktop/src/renderer/src/modules/auth/LoginModalContent.tsx index dffbc2ff1..3dad45d97 100644 --- a/apps/desktop/src/renderer/src/modules/auth/LoginModalContent.tsx +++ b/apps/desktop/src/renderer/src/modules/auth/LoginModalContent.tsx @@ -1,3 +1,4 @@ +import { Spring } from "@follow/components/constants/spring.js" import { useMobile } from "@follow/components/hooks/useMobile.js" import { Folo } from "@follow/components/icons/folo.js" import { Logo } from "@follow/components/icons/logo.js" @@ -10,6 +11,7 @@ import { TooltipTrigger, } from "@follow/components/ui/tooltip/index.js" import type { LoginRuntime } from "@follow/shared/auth" +import { stopPropagation } from "@follow/utils/dom" import { clsx } from "@follow/utils/utils" import { m } from "motion/react" import { useTranslation } from "react-i18next" @@ -104,10 +106,14 @@ export const LoginModalContent = (props: LoginModalContentProps) => { -
+
{Inner}
diff --git a/apps/desktop/src/renderer/src/modules/boost/modal.tsx b/apps/desktop/src/renderer/src/modules/boost/modal.tsx index 59bff72e3..da1def73e 100644 --- a/apps/desktop/src/renderer/src/modules/boost/modal.tsx +++ b/apps/desktop/src/renderer/src/modules/boost/modal.tsx @@ -1,10 +1,10 @@ +import { Spring } from "@follow/components/constants/spring.js" import { Button } from "@follow/components/ui/button/index.js" import { LoadingWithIcon } from "@follow/components/ui/loading/index.jsx" import { from } from "dnum" import { AnimatePresence, m } from "motion/react" import { useCallback, useState } from "react" -import { softSpringPreset } from "~/components/ui/constants/spring" import { useCurrentModal } from "~/components/ui/modal/stacked/hooks" import { useI18n } from "~/hooks/common" import { useBoostFeedMutation, useBoostStatusQuery } from "~/modules/boost/query" @@ -84,7 +84,11 @@ export const BoostModalContent = ({ feedId }: { feedId: string }) => { {boostFeedMutation.isSuccess ? ( <> - + {t("boost.boost_success_thanks")}