From 243378d14f99d4a0b37578432220eb24c683d556 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=8C=E8=B4=A7=E6=9C=BA=E5=99=A8=E4=BA=BA?= Date: Mon, 18 May 2026 15:32:51 +0800 Subject: [PATCH 1/4] expose scrollTop in extraRender info --- src/List.tsx | 1 + src/interface.ts | 2 ++ tests/scroll.test.js | 24 ++++++++++++++++++++++++ 3 files changed, 27 insertions(+) diff --git a/src/List.tsx b/src/List.tsx index ece1ccb6..79050fbc 100644 --- a/src/List.tsx +++ b/src/List.tsx @@ -558,6 +558,7 @@ export function RawList(props: ListProps, ref: React.Ref) { end, virtual: inVirtual, offsetX: offsetLeft, + scrollTop: offsetTop, offsetY: fillerOffset, rtl: isRTL, getSize, diff --git a/src/interface.ts b/src/interface.ts index e0fd765d..4ff37a78 100644 --- a/src/interface.ts +++ b/src/interface.ts @@ -21,6 +21,8 @@ export interface ExtraRenderInfo { virtual: boolean; /** Used for `scrollWidth` tell the horizontal offset */ offsetX: number; + /** Current vertical scroll offset */ + scrollTop: number; offsetY: number; rtl: boolean; diff --git a/tests/scroll.test.js b/tests/scroll.test.js index 7eba007e..5423ab3c 100644 --- a/tests/scroll.test.js +++ b/tests/scroll.test.js @@ -113,6 +113,30 @@ describe('List.Scroll', () => { wrapper.unmount(); }); + + it('passes current scrollTop to extraRender', () => { + const listRef = React.createRef(); + const extraRender = jest.fn(() => null); + const wrapper = genList({ + itemHeight: 20, + height: 100, + data: genData(100), + ref: listRef, + extraRender, + }); + + listRef.current.scrollTo(80); + jest.runAllTimers(); + wrapper.update(); + + expect(extraRender).toHaveBeenLastCalledWith( + expect.objectContaining({ + scrollTop: 80, + }), + ); + + wrapper.unmount(); + }); }); describe('scroll to object', () => { From 8a6639a786d4e7c02b5693c9e0652685a7a08e28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=8C=E8=B4=A7=E6=9C=BA=E5=99=A8=E4=BA=BA?= Date: Mon, 18 May 2026 15:43:47 +0800 Subject: [PATCH 2/4] clarify extra render scroll offsets --- src/interface.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/interface.ts b/src/interface.ts index 4ff37a78..fd127446 100644 --- a/src/interface.ts +++ b/src/interface.ts @@ -19,10 +19,11 @@ export interface ExtraRenderInfo { end: number; /** Is current in virtual render */ virtual: boolean; - /** Used for `scrollWidth` tell the horizontal offset */ + /** Horizontal scroll offset applied to rendered items when `scrollWidth` is set */ offsetX: number; - /** Current vertical scroll offset */ + /** Current vertical scrollTop of the holder element */ scrollTop: number; + /** Vertical translate offset of the rendered filler content */ offsetY: number; rtl: boolean; From 6fb133deeb67cf2daf2eaa252d3076995cb0bd84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=8C=E8=B4=A7=E6=9C=BA=E5=99=A8=E4=BA=BA?= Date: Mon, 18 May 2026 15:46:49 +0800 Subject: [PATCH 3/4] add Chinese extra render offset docs --- src/interface.ts | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/interface.ts b/src/interface.ts index fd127446..a7c46289 100644 --- a/src/interface.ts +++ b/src/interface.ts @@ -19,11 +19,20 @@ export interface ExtraRenderInfo { end: number; /** Is current in virtual render */ virtual: boolean; - /** Horizontal scroll offset applied to rendered items when `scrollWidth` is set */ + /** + * Horizontal scroll offset applied to rendered items when `scrollWidth` is set. + * 当设置 `scrollWidth` 时,应用到已渲染元素上的横向滚动偏移量。 + */ offsetX: number; - /** Current vertical scrollTop of the holder element */ + /** + * Current vertical scrollTop of the holder element. + * holder 元素当前真实的纵向 `scrollTop`,表示视口滚动到了哪里。 + */ scrollTop: number; - /** Vertical translate offset of the rendered filler content */ + /** + * Vertical translate offset of the rendered filler content. + * 已渲染 filler 内容的纵向 `translateY` 偏移量,表示这一段内容被平移到虚拟列表中的哪个位置。 + */ offsetY: number; rtl: boolean; From eadf1783a530da1c47b8e3e397d75947ab2c5841 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=8C=E8=B4=A7=E6=9C=BA=E5=99=A8=E4=BA=BA?= Date: Mon, 18 May 2026 16:00:05 +0800 Subject: [PATCH 4/4] fix util imports for compile --- src/List.tsx | 3 +-- src/ScrollBar.tsx | 2 +- src/hooks/useFrameWheel.ts | 2 +- src/hooks/useMobileTouchMove.ts | 2 +- src/hooks/useScrollDrag.ts | 2 +- src/hooks/useScrollTo.tsx | 4 +--- src/index.ts | 3 ++- 7 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/List.tsx b/src/List.tsx index 79050fbc..63816da5 100644 --- a/src/List.tsx +++ b/src/List.tsx @@ -1,8 +1,7 @@ import { clsx } from 'clsx'; import type { ResizeObserverProps } from '@rc-component/resize-observer'; import ResizeObserver from '@rc-component/resize-observer'; -import { useEvent } from '@rc-component/util'; -import useLayoutEffect from '@rc-component/util/lib/hooks/useLayoutEffect'; +import { useEvent, useLayoutEffect } from '@rc-component/util'; import * as React from 'react'; import { useRef, useState } from 'react'; import { flushSync } from 'react-dom'; diff --git a/src/ScrollBar.tsx b/src/ScrollBar.tsx index d8a41480..ce4ff6fa 100644 --- a/src/ScrollBar.tsx +++ b/src/ScrollBar.tsx @@ -1,5 +1,5 @@ import { clsx } from 'clsx'; -import raf from '@rc-component/util/lib/raf'; +import { raf } from '@rc-component/util'; import * as React from 'react'; import { getPageXY } from './hooks/useScrollDrag'; diff --git a/src/hooks/useFrameWheel.ts b/src/hooks/useFrameWheel.ts index 7dea2ef5..901a39a7 100644 --- a/src/hooks/useFrameWheel.ts +++ b/src/hooks/useFrameWheel.ts @@ -1,4 +1,4 @@ -import raf from '@rc-component/util/lib/raf'; +import { raf } from '@rc-component/util'; import { useRef } from 'react'; import isFF from '../utils/isFirefox'; import useOriginScroll from './useOriginScroll'; diff --git a/src/hooks/useMobileTouchMove.ts b/src/hooks/useMobileTouchMove.ts index 3a787f80..cd3dc365 100644 --- a/src/hooks/useMobileTouchMove.ts +++ b/src/hooks/useMobileTouchMove.ts @@ -1,4 +1,4 @@ -import useLayoutEffect from '@rc-component/util/lib/hooks/useLayoutEffect'; +import { useLayoutEffect } from '@rc-component/util'; import type * as React from 'react'; import { useRef } from 'react'; diff --git a/src/hooks/useScrollDrag.ts b/src/hooks/useScrollDrag.ts index fd7c7019..08510c5f 100644 --- a/src/hooks/useScrollDrag.ts +++ b/src/hooks/useScrollDrag.ts @@ -1,4 +1,4 @@ -import raf from '@rc-component/util/lib/raf'; +import { raf } from '@rc-component/util'; import * as React from 'react'; function smoothScrollOffset(offset: number) { diff --git a/src/hooks/useScrollTo.tsx b/src/hooks/useScrollTo.tsx index 54d2ae94..3dd85182 100644 --- a/src/hooks/useScrollTo.tsx +++ b/src/hooks/useScrollTo.tsx @@ -1,10 +1,8 @@ /* eslint-disable no-param-reassign */ import * as React from 'react'; -import raf from '@rc-component/util/lib/raf'; +import { raf, useLayoutEffect, warning } from '@rc-component/util'; import type { GetKey } from '../interface'; import type CacheMap from '../utils/CacheMap'; -import useLayoutEffect from '@rc-component/util/lib/hooks/useLayoutEffect'; -import { warning } from '@rc-component/util'; const MAX_TIMES = 10; diff --git a/src/index.ts b/src/index.ts index a312aa0d..bbcd8f3c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,5 +1,6 @@ import List from './List'; -export type { ListRef, ListProps } from './List'; +export type { ListRef, ListProps, ScrollConfig, ScrollTo } from './List'; +export { default as MockList } from './mock'; export default List;