From 5e846b9015181a4e6be714984cc8f674d16c504b Mon Sep 17 00:00:00 2001 From: Innei Date: Fri, 12 Jul 2024 12:45:11 +0800 Subject: [PATCH] fix: feed column view initial status in reduce motion mode Signed-off-by: Innei --- src/renderer/src/atoms/sidebar.ts | 13 +++++- .../src/modules/feed-column/index.tsx | 40 ++++++++++++++++--- 2 files changed, 45 insertions(+), 8 deletions(-) diff --git a/src/renderer/src/atoms/sidebar.ts b/src/renderer/src/atoms/sidebar.ts index 4aa990f99..dfb8e69e4 100644 --- a/src/renderer/src/atoms/sidebar.ts +++ b/src/renderer/src/atoms/sidebar.ts @@ -1,7 +1,9 @@ -import { FeedViewType } from "@renderer/lib/enum" +import { getRouteParams } from "@renderer/hooks/biz/useRouteParams" +import type { FeedViewType } from "@renderer/lib/enum" import { createAtomHooks } from "@renderer/lib/jotai" import { atom } from "jotai" +const viewAtom = atom(-1) const [ , useSidebarActiveView, @@ -9,7 +11,7 @@ const [ useSetSidebarActiveView, getSidebarActiveView, setSidebarActiveView, -] = createAtomHooks(atom(FeedViewType.Articles)) +] = createAtomHooks(viewAtom) export { getSidebarActiveView, @@ -18,3 +20,10 @@ export { useSidebarActiveView, useSidebarActiveViewValue, } + +viewAtom.onMount = () => { + const { view } = getRouteParams() + if (view !== undefined) { + setSidebarActiveView(view) + } +} diff --git a/src/renderer/src/modules/feed-column/index.tsx b/src/renderer/src/modules/feed-column/index.tsx index e94abd0ff..d82bed275 100644 --- a/src/renderer/src/modules/feed-column/index.tsx +++ b/src/renderer/src/modules/feed-column/index.tsx @@ -12,6 +12,7 @@ import { Routes } from "@renderer/lib/enum" import { shortcuts } from "@renderer/lib/shortcuts" import { clamp, cn } from "@renderer/lib/utils" import { useWheel } from "@use-gesture/react" +import type { MotionValue } from "framer-motion" import { m, useSpring } from "framer-motion" import { Lethargy } from "lethargy" import { useCallback, useLayoutEffect, useRef } from "react" @@ -60,6 +61,7 @@ export function FeedColumn() { }, [active, navigateBackHome, spring], ) + useLayoutEffect(() => { const { view } = getRouteParams() if (view !== undefined) { @@ -115,7 +117,6 @@ export function FeedColumn() { const normalStyle = !window.electron || window.electron.process.platform !== "darwin" - const reduceMotion = useReduceMotion() return (
- + {views.map((item, index) => (
))} - +
{APP_VERSION?.[0] === "0" && (
@@ -208,3 +206,33 @@ export function FeedColumn() { ) } + +const SwipeWrapper: Component<{ + active: number + spring: MotionValue +}> = ({ children, active, spring }) => { + const reduceMotion = useReduceMotion() + + if (reduceMotion) { + return ( +
+ {children} +
+ ) + } + return ( + + {children} + + ) +}