@@ -5,7 +5,7 @@ import { AutoSizer } from "react-virtualized-auto-sizer";
55import AlphabetIndex from "./AlphabetIndex" ;
66import { RowComponent } from "./FileListRow" ;
77import { FILE_ITEM_CONFIG , LIST_HEIGHT_CONFIG } from "./utils/fileListConfig" ;
8- import { calculateLayoutMetrics } from "./utils/fileListLayout" ;
8+ import { calculateLayoutMetrics , getListPadding , getRowMetrics } from "./utils/fileListLayout" ;
99import type { VirtualListItemData , FileListLayoutMetrics } from "./utils/types" ;
1010import type { GitHubContent } from "@/types" ;
1111import { theme } from "@/utils" ;
@@ -70,17 +70,8 @@ const FileList = React.memo<FileListProps>(
7070
7171 // 计算每个文件项的高度(包括间距)
7272 // 这个计算需要与 FileListItem 的实际高度保持一致
73- const rowHeight = useMemo ( ( ) => {
74- // 基础高度
75- const baseHeight = isSmallScreen
76- ? FILE_ITEM_CONFIG . baseHeight . xs
77- : FILE_ITEM_CONFIG . baseHeight . sm ;
78-
79- // 行间距(上下各分一半)
80- const rowGap = FILE_ITEM_CONFIG . spacing . marginBottom ;
81-
82- // 计算总高度:基础高度 + 行间距
83- return baseHeight + rowGap ;
73+ const { rowHeight, rowPaddingBottom } = useMemo ( ( ) => {
74+ return getRowMetrics ( isSmallScreen ) ;
8475 } , [ isSmallScreen ] ) ;
8576
8677 /**
@@ -200,6 +191,7 @@ const FileList = React.memo<FileListProps>(
200191 isScrolling,
201192 scrollSpeed,
202193 highlightedIndex,
194+ rowPaddingBottom,
203195 } ) ,
204196 [
205197 contents ,
@@ -214,26 +206,17 @@ const FileList = React.memo<FileListProps>(
214206 isScrolling ,
215207 scrollSpeed ,
216208 highlightedIndex ,
209+ rowPaddingBottom ,
217210 ] ,
218211 ) ;
219212
220213 // 简化的列表内边距计算
221- const listPadding = useMemo ( ( ) : { paddingTop : number ; paddingBottom : number } => {
222- // 非滚动模式:使用固定的对称内边距,稍微增加一点
223- if ( ! needsScrolling ) {
224- const padding = isSmallScreen ? 16 : 20 ;
225- return {
226- paddingTop : padding - 4 ,
227- paddingBottom : padding ,
228- } ;
229- }
230-
231- // 滚动模式:使用较小的内边距
232- return {
233- paddingTop : 0 ,
234- paddingBottom : 8 ,
235- } ;
236- } , [ needsScrolling , isSmallScreen ] ) ;
214+ // 列表内边距规则集中管理,区分滚动与非滚动模式。
215+ const listPadding = useMemo (
216+ ( ) : { paddingTop : number ; paddingBottom : number } =>
217+ getListPadding ( needsScrolling , isSmallScreen ) ,
218+ [ needsScrolling , isSmallScreen ] ,
219+ ) ;
237220
238221 // 处理滚动事件(监听列表容器)
239222 React . useEffect ( ( ) => {
0 commit comments