feat: smoother entry header animation

- Removed unused imports and components from AIEntryLayout, simplifying the layout structure.
- Updated EntryContent to adjust height dynamically and improved the scroll area with a new viewport class.
- Enhanced EntryHeader to integrate a scroll-to-exit hint directly into the header, improving user guidance.
- Refactored EntryHeaderRoot to support motion styles for smoother animations.

These changes collectively improve code clarity and enhance the user experience by providing better navigation cues and layout responsiveness.
This commit is contained in:
DIYgod
2025-08-23 01:20:27 +08:00
parent 28ddb76df4
commit 23664e6ceb
5 changed files with 81 additions and 52 deletions
@@ -1,11 +1,9 @@
import { Spring } from "@follow/components/constants/spring.js"
import { Button } from "@follow/components/ui/button/index.js"
import { PanelSplitter } from "@follow/components/ui/divider/index.js"
import { defaultUISettings } from "@follow/shared/settings/defaults"
import { cn } from "@follow/utils"
import { AnimatePresence } from "motion/react"
import { useCallback, useEffect, useMemo, useRef } from "react"
import { useTranslation } from "react-i18next"
import { useResizable } from "react-resizable-layout"
import { useParams } from "react-router"
@@ -19,14 +17,11 @@ import { EntryContent } from "~/modules/entry-content/components/entry-content"
import { AppLayoutGridContainerProvider } from "~/providers/app-grid-layout-container-provider"
import { AIChatRoot } from "../ai-chat/components/layouts/AIChatRoot"
import { useEntryContentScrollToTop } from "../entry-content/atoms"
import { setScrollToExitTutorialSeen } from "./atoms/tutorial"
import { ScrollToExitTutorial } from "./components/ScrollToExitTutorial"
import { EntryColumn } from "./index"
const AIEntryLayoutImpl = () => {
const { entryId } = useParams()
const { t } = useTranslation()
const navigate = useNavigateEntry()
const panelStyle = useAIChatPanelStyle()
@@ -120,8 +115,6 @@ const AIEntryLayoutImpl = () => {
window.dispatchEvent(new Event("resize"))
},
})
const isAtTop = !!useEntryContentScrollToTop()
return (
<div className="relative flex min-w-0 grow">
<div className={cn("h-full flex-1", panelStyle === AIChatPanelStyle.Fixed && "border-r")}>
@@ -141,35 +134,7 @@ const AIEntryLayoutImpl = () => {
transition={Spring.presets.smooth}
className="bg-theme-background absolute inset-0 z-10 border-l"
>
<AnimatePresence>
{/* Scroll hint indicator */}
{isAtTop && (
<m.div
className="center z-50"
initial={{ y: -30, height: 0 }}
animate={{ y: 0, height: "auto" }}
exit={{ y: -30, height: 0 }}
>
<Button
variant="ghost"
size="sm"
onClick={() => navigate({ entryId: null })}
buttonClassName="transform cursor-pointer select-none no-drag-region w-full py-3 rounded-none"
aria-label="Scroll up or click to exit"
>
<div className="text-text flex items-center gap-2 rounded-full font-medium">
<i className="i-mgc-up-cute-re repeat-[2] text-base" />
<span>{t("entry.scroll_up_to_exit")}</span>
</div>
</Button>
</m.div>
)}
</AnimatePresence>
{/* First-time user tutorial for scroll-to-exit */}
<ScrollToExitTutorial show={!!realEntryId && isAtTop} />
<EntryContent entryId={realEntryId} className="h-[calc(100%-2.25rem)]" />
<EntryContent entryId={realEntryId} className="h-full" />
</m.div>
)}
</AnimatePresence>
@@ -112,7 +112,7 @@ const EntryContentImpl: Component<EntryContentProps> = ({
<EntryCommandShortcutRegister entryId={entryId} view={view} />
<AIEntryHeader
entryId={entryId}
className={cn("@container h-[55px] shrink-0 px-3", classNames?.header)}
className={cn("absolute inset-x-0 top-0", classNames?.header)}
compact={compact}
/>
<div className="w-full" ref={setPanelPortalElement} />
@@ -129,7 +129,7 @@ const EntryContentImpl: Component<EntryContentProps> = ({
/>
</RootPortal>
{/* <EntryTimeline entryId={entryId} className="top-48" /> */}
<EntryScrollArea scrollerRef={scrollerRef}>
<EntryScrollArea scrollerRef={scrollerRef} viewportClassName="pt-[95px]">
{/* Indicator for the entry */}
{!isZenMode && isInHasTimelineView && (
<>
@@ -211,7 +211,8 @@ export const EntryContent = memo(EntryContentImpl)
const EntryScrollArea: Component<{
scrollerRef: React.RefObject<HTMLDivElement | null>
}> = ({ children, className, scrollerRef }) => {
viewportClassName?: string
}> = ({ children, className, scrollerRef, viewportClassName }) => {
const isInPeekModal = useInPeekModal()
if (isInPeekModal) {
@@ -228,6 +229,7 @@ const EntryScrollArea: Component<{
)}
scrollbarClassName="mr-[1.5px] print:hidden"
ref={scrollerRef}
viewportClassName={viewportClassName}
>
{children}
</ScrollArea.ScrollArea>
@@ -1,4 +1,12 @@
import { Button } from "@follow/components/ui/button/index.js"
import { cn } from "@follow/utils"
import { memo } from "react"
import { useTranslation } from "react-i18next"
import { m } from "~/components/common/Motion"
import { useNavigateEntry } from "~/hooks/biz/useNavigateEntry"
import { ScrollToExitTutorial } from "~/modules/entry-column/components/ScrollToExitTutorial"
import { useEntryContentScrollToTop } from "~/modules/entry-content/atoms"
import { EntryHeaderRoot } from "./internal/context"
import { EntryHeaderActionsContainer } from "./internal/EntryHeaderActionsContainer"
@@ -7,17 +15,59 @@ import { EntryHeaderReadHistory } from "./internal/EntryHeaderReadHistory"
import type { EntryHeaderProps } from "./types"
function EntryHeaderImpl({ entryId, className, compact }: EntryHeaderProps) {
const { t } = useTranslation()
const navigate = useNavigateEntry()
const isAtTop = !!useEntryContentScrollToTop()
return (
<EntryHeaderRoot entryId={entryId} className={className} compact={compact}>
<EntryHeaderReadHistory />
<div
className="relative z-10 flex w-full items-center justify-between gap-3"
data-hide-in-print
<>
<EntryHeaderRoot
entryId={entryId}
className={cn(
className,
"@container bg-background z-10 h-[95px] shrink-0 flex-col gap-0 px-3",
)}
compact={compact}
style={{
y: isAtTop ? 0 : -40,
}}
>
<EntryHeaderMeta />
<EntryHeaderActionsContainer />
</div>
</EntryHeaderRoot>
{/* Scroll to exit hint - integrated into header to maintain consistent height */}
<m.div
className="z-50 flex h-10 items-center justify-center"
style={{
opacity: isAtTop ? 1 : 0,
}}
>
<Button
variant="ghost"
size="sm"
onClick={() => navigate({ entryId: null })}
buttonClassName="h-full cursor-pointer select-none no-drag-region rounded-none px-6"
aria-label="Scroll up or click to exit"
>
<div className="text-text flex items-center gap-2 rounded-full font-medium">
<i className="i-mgc-up-cute-re repeat-[2] text-base" />
<span>{t("entry.scroll_up_to_exit")}</span>
</div>
</Button>
</m.div>
<div className={cn("center relative h-[55px] w-full")}>
<EntryHeaderReadHistory className="left-0" />
<div
className={cn("relative z-10 flex w-full items-center justify-between gap-3")}
data-hide-in-print
>
<EntryHeaderMeta />
<EntryHeaderActionsContainer />
</div>
</div>
{/* First-time user tutorial for scroll-to-exit */}
<ScrollToExitTutorial show={!!entryId && isAtTop} />
</EntryHeaderRoot>
</>
)
}
@@ -8,7 +8,7 @@ import { useEntryContentScrollToTop } from "../../../atoms"
import { EntryReadHistory } from "../../entry-read-history"
import { useEntryHeaderContext } from "./context"
function EntryHeaderReadHistoryImpl() {
function EntryHeaderReadHistoryImpl({ className }: { className?: string }) {
const { entryId } = useEntryHeaderContext()
const { view } = useRouteParams()
const isAtTop = useEntryContentScrollToTop()
@@ -21,6 +21,7 @@ function EntryHeaderReadHistoryImpl() {
"zen-mode-macos:left-12 text-body absolute left-5 top-0 flex h-full items-center gap-2 leading-none",
"visible z-[11]",
isWide && "static",
className,
)}
>
<EntryReadHistory entryId={entryId} />
@@ -1,8 +1,11 @@
import { useHasEntry } from "@follow/store/entry/hooks"
import { cn } from "@follow/utils/utils"
import type { MotionStyle } from "motion/react"
import type { ReactNode } from "react"
import { createContext, memo, use, useMemo } from "react"
import { m } from "~/components/common/Motion"
import { useEntryContentScrollToTop, useEntryTitleMeta } from "../../../atoms"
import type { EntryHeaderProps } from "../types"
@@ -21,9 +24,16 @@ export function useEntryHeaderContext() {
export interface EntryHeaderRootProps extends EntryHeaderProps {
children: ReactNode
style?: MotionStyle
}
function EntryHeaderRootImpl({ entryId, className, compact, children }: EntryHeaderRootProps) {
function EntryHeaderRootImpl({
entryId,
className,
compact,
children,
style,
}: EntryHeaderRootProps) {
const hasEntry = useHasEntry(entryId)
const entryTitleMeta = useEntryTitleMeta()
const isAtTop = !!useEntryContentScrollToTop()
@@ -35,16 +45,17 @@ function EntryHeaderRootImpl({ entryId, className, compact, children }: EntryHea
return (
<EntryHeaderContext value={contextValue}>
<div
<m.div
data-hide-in-print
className={cn(
"zen-mode-macos:ml-margin-macos-traffic-light-x text-text-secondary relative flex min-w-0 items-center justify-between gap-3 overflow-hidden text-lg duration-200",
shouldShowMeta && "border-border border-b",
className,
)}
style={style}
>
{children}
</div>
</m.div>
</EntryHeaderContext>
)
}