From 0a644730bef2165ef75fb9d2eca2ee9c20ab66bd Mon Sep 17 00:00:00 2001 From: Whitewater Date: Sun, 12 Jan 2025 00:16:11 +0800 Subject: [PATCH] refactor: rename sticky check functions for clarity (#2542) --- .../src/modules/entry-column/list.tsx | 26 ++++++++----------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/apps/renderer/src/modules/entry-column/list.tsx b/apps/renderer/src/modules/entry-column/list.tsx index 94c95ba76a..3b61d4b764 100644 --- a/apps/renderer/src/modules/entry-column/list.tsx +++ b/apps/renderer/src/modules/entry-column/list.tsx @@ -1,6 +1,6 @@ import { EmptyIcon } from "@follow/components/icons/empty.jsx" import { useScrollViewElement } from "@follow/components/ui/scroll-area/hooks.js" -import { FeedViewType } from "@follow/constants" +import type { FeedViewType } from "@follow/constants" import { useTypeScriptHappyCallback } from "@follow/hooks" import { LRUCache } from "@follow/utils/lru-cache" import type { Range, VirtualItem, Virtualizer } from "@tanstack/react-virtual" @@ -161,8 +161,8 @@ export const EntryList: FC = memo( }) const activeStickyIndexRef = useRef(0) - const isActiveSticky = (index: number) => activeStickyIndexRef.current === index - const isSticky = (index: number) => stickyIndexes.includes(index) + const checkIsActiveSticky = (index: number) => activeStickyIndexRef.current === index + const checkIsStickyItem = (index: number) => stickyIndexes.includes(index) const virtualItems = rowVirtualizer.getVirtualItems() useEffect(() => { @@ -242,20 +242,20 @@ export const EntryList: FC = memo( ) } - const activeSticky = isActiveSticky(virtualRow.index) - const sticky = isSticky(virtualRow.index) + const isStickyItem = checkIsStickyItem(virtualRow.index) + const isActiveStickyItem = !isScrollTop && checkIsActiveSticky(virtualRow.index) return ( - {sticky && ( + {isStickyItem && (
= memo( >
)} @@ -272,11 +272,7 @@ export const EntryList: FC = memo( className="absolute left-0 top-0 w-full will-change-transform" style={{ transform, - paddingTop: sticky - ? view === FeedViewType.SocialMedia - ? "3.5rem" - : "1.5rem" - : undefined, + paddingTop: isStickyItem ? "1.75rem" : undefined, }} ref={rowVirtualizer.measureElement} data-index={virtualRow.index}