Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/List.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -558,6 +557,7 @@ export function RawList<T>(props: ListProps<T>, ref: React.Ref<ListRef>) {
end,
virtual: inVirtual,
offsetX: offsetLeft,
scrollTop: offsetTop,
offsetY: fillerOffset,
rtl: isRTL,
getSize,
Expand Down
2 changes: 1 addition & 1 deletion src/ScrollBar.tsx
Original file line number Diff line number Diff line change
@@ -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';

Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useFrameWheel.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useMobileTouchMove.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useScrollDrag.ts
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down
4 changes: 1 addition & 3 deletions src/hooks/useScrollTo.tsx
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -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;
14 changes: 13 additions & 1 deletion src/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,20 @@ 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.
* 当设置 `scrollWidth` 时,应用到已渲染元素上的横向滚动偏移量。
*/
offsetX: number;
/**
* Current vertical scrollTop of the holder element.
* holder 元素当前真实的纵向 `scrollTop`,表示视口滚动到了哪里。
*/
scrollTop: number;
/**
* Vertical translate offset of the rendered filler content.
* 已渲染 filler 内容的纵向 `translateY` 偏移量,表示这一段内容被平移到虚拟列表中的哪个位置。
*/
offsetY: number;

rtl: boolean;
Expand Down
24 changes: 24 additions & 0 deletions tests/scroll.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
Loading