@@ -2,6 +2,7 @@ import { useMobile } from "@follow/components/hooks/useMobile.js"
22import { useScrollViewElement } from "@follow/components/ui/scroll-area/hooks.js"
33import { FeedViewType } from "@follow/constants"
44import { useTypeScriptHappyCallback } from "@follow/hooks"
5+ import { shouldRenderScrollMarkReadEndSpacer } from "@follow/shared/scroll-mark-read"
56import { LRUCache } from "@follow/utils/lru-cache"
67import type { Range , VirtualItem , Virtualizer } from "@tanstack/react-virtual"
78import { useVirtualizer } from "@tanstack/react-virtual"
@@ -20,6 +21,7 @@ import { useUISettingKey } from "~/atoms/settings/ui"
2021import { MediaContainerWidthProvider } from "~/components/ui/media/MediaContainerWidthProvider"
2122
2223import { EntryItemSkeleton } from "./EntryItemSkeleton"
24+ import { useScrollMarkReadEndPadding } from "./hooks/useScrollMarkReadEndPadding"
2325import { EntryItem } from "./item"
2426import { PictureMasonry } from "./Items/picture-masonry"
2527import type { EntryListProps } from "./list"
@@ -117,6 +119,11 @@ const VirtualGridImpl: FC<
117119
118120 const pictureViewImageOnly = useUISettingKey ( "pictureViewImageOnly" )
119121 const isImageOnly = view === FeedViewType . Pictures && pictureViewImageOnly
122+ const hasEndSpacer = shouldRenderScrollMarkReadEndSpacer ( {
123+ entryCount : entriesIds . length ,
124+ hasNextPage,
125+ } )
126+ const endSpacerHeight = useScrollMarkReadEndPadding ( scrollRef , hasEndSpacer )
120127
121128 // Calculate rows based on entries
122129 const rows = useMemo ( ( ) => {
@@ -129,6 +136,9 @@ const VirtualGridImpl: FC<
129136
130137 const rowCacheKey = `${ feedId } -row`
131138 const columnCacheKey = `${ feedId } -column`
139+ const footerRowIndex = rows . length + ( hasNextPage ? 1 : 0 )
140+ const rowCount = footerRowIndex + ( Footer ? 1 : 0 )
141+ const estimatedRowHeight = columns [ 0 ] ! / ( ratioMap [ view ] ?? 1 ) + ( ! isImageOnly ? 58 : 0 )
132142
133143 const columnVirtualizer = useVirtualizer ( {
134144 horizontal : true ,
@@ -150,10 +160,8 @@ const VirtualGridImpl: FC<
150160 } )
151161
152162 const rowVirtualizer = useVirtualizer ( {
153- count : rows . length + ( hasNextPage ? 1 : 0 ) + ( Footer ? 1 : 0 ) ,
154- estimateSize : ( ) => {
155- return columns [ 0 ] ! / ( ratioMap [ view ] ?? 1 ) + ( ! isImageOnly ? 58 : 0 )
156- } ,
163+ count : rowCount ,
164+ estimateSize : ( ) => estimatedRowHeight ,
157165 overscan : 5 ,
158166 gap : 8 ,
159167 getScrollElement : ( ) => scrollRef ,
@@ -223,12 +231,11 @@ const VirtualGridImpl: FC<
223231 < div
224232 className = "relative mx-4"
225233 style = { {
226- height : `${ rowVirtualizer . getTotalSize ( ) } px` ,
234+ height : `${ rowVirtualizer . getTotalSize ( ) + endSpacerHeight } px` ,
227235 } }
228236 >
229237 { rowVirtualizer . getVirtualItems ( ) . map ( ( virtualRow ) => {
230- const footerRowIndex = rows . length + ( hasNextPage ? 1 : 0 )
231- const isFooterRow = Footer && virtualRow . key === footerRowIndex
238+ const isFooterRow = Footer && virtualRow . index === footerRowIndex
232239
233240 if ( isFooterRow && ready ) {
234241 return (
0 commit comments