|
1 |
| -import * as React from 'react'; |
2 |
| -import { useRef, useState } from 'react'; |
3 |
| -import { flushSync } from 'react-dom'; |
4 | 1 | import classNames from 'classnames';
|
5 | 2 | import type { ResizeObserverProps } from 'rc-resize-observer';
|
6 | 3 | import ResizeObserver from 'rc-resize-observer';
|
7 |
| -import Filler from './Filler'; |
| 4 | +import { useEvent } from 'rc-util'; |
| 5 | +import useLayoutEffect from 'rc-util/lib/hooks/useLayoutEffect'; |
| 6 | +import * as React from 'react'; |
| 7 | +import { useRef, useState } from 'react'; |
| 8 | +import { flushSync } from 'react-dom'; |
8 | 9 | import type { InnerProps } from './Filler';
|
9 |
| -import type { ScrollBarDirectionType, ScrollBarRef } from './ScrollBar'; |
10 |
| -import ScrollBar from './ScrollBar'; |
11 |
| -import type { RenderFunc, SharedConfig, GetKey, ExtraRenderInfo } from './interface'; |
| 10 | +import Filler from './Filler'; |
12 | 11 | import useChildren from './hooks/useChildren';
|
13 |
| -import useHeights from './hooks/useHeights'; |
14 |
| -import useScrollTo from './hooks/useScrollTo'; |
15 |
| -import type { ScrollPos, ScrollTarget } from './hooks/useScrollTo'; |
16 | 12 | import useDiffItem from './hooks/useDiffItem';
|
17 | 13 | import useFrameWheel from './hooks/useFrameWheel';
|
| 14 | +import { useGetSize } from './hooks/useGetSize'; |
| 15 | +import useHeights from './hooks/useHeights'; |
18 | 16 | import useMobileTouchMove from './hooks/useMobileTouchMove';
|
19 | 17 | import useOriginScroll from './hooks/useOriginScroll';
|
20 |
| -import useLayoutEffect from 'rc-util/lib/hooks/useLayoutEffect'; |
| 18 | +import type { ScrollPos, ScrollTarget } from './hooks/useScrollTo'; |
| 19 | +import useScrollTo from './hooks/useScrollTo'; |
| 20 | +import type { ExtraRenderInfo, GetKey, RenderFunc, SharedConfig } from './interface'; |
| 21 | +import type { ScrollBarDirectionType, ScrollBarRef } from './ScrollBar'; |
| 22 | +import ScrollBar from './ScrollBar'; |
21 | 23 | import { getSpinSize } from './utils/scrollbarUtil';
|
22 |
| -import { useEvent } from 'rc-util'; |
23 |
| -import { useGetSize } from './hooks/useGetSize'; |
24 | 24 |
|
25 | 25 | const EMPTY_DATA = [];
|
26 | 26 |
|
@@ -133,8 +133,14 @@ export function RawList<T>(props: ListProps<T>, ref: React.Ref<ListRef>) {
|
133 | 133 |
|
134 | 134 | // ================================= MISC =================================
|
135 | 135 | const useVirtual = !!(virtual !== false && height && itemHeight);
|
136 |
| - const containerHeight = React.useMemo(() => Object.values(heights.maps).reduce((total, curr) => total + curr, 0), [heights.id, heights.maps]); |
137 |
| - const inVirtual = useVirtual && data && (Math.max(itemHeight * data.length, containerHeight) > height || !!scrollWidth); |
| 136 | + const containerHeight = React.useMemo( |
| 137 | + () => Object.values(heights.maps).reduce((total, curr) => total + curr, 0), |
| 138 | + [heights.id, heights.maps], |
| 139 | + ); |
| 140 | + const inVirtual = |
| 141 | + useVirtual && |
| 142 | + data && |
| 143 | + (Math.max(itemHeight * data.length, containerHeight) > height || !!scrollWidth); |
138 | 144 | const isRTL = direction === 'rtl';
|
139 | 145 |
|
140 | 146 | const mergedClassName = classNames(prefixCls, { [`${prefixCls}-rtl`]: isRTL }, className);
|
@@ -312,9 +318,9 @@ export function RawList<T>(props: ListProps<T>, ref: React.Ref<ListRef>) {
|
312 | 318 |
|
313 | 319 | const lastVirtualScrollInfoRef = useRef(getVirtualScrollInfo());
|
314 | 320 |
|
315 |
| - const triggerScroll = useEvent(() => { |
| 321 | + const triggerScroll = useEvent((params?: { x?: number; y?: number }) => { |
316 | 322 | if (onVirtualScroll) {
|
317 |
| - const nextInfo = getVirtualScrollInfo(); |
| 323 | + const nextInfo = { ...getVirtualScrollInfo(), ...params }; |
318 | 324 |
|
319 | 325 | // Trigger when offset changed
|
320 | 326 | if (
|
@@ -425,9 +431,9 @@ export function RawList<T>(props: ListProps<T>, ref: React.Ref<ListRef>) {
|
425 | 431 | // Sync scroll left
|
426 | 432 | useLayoutEffect(() => {
|
427 | 433 | if (scrollWidth) {
|
428 |
| - setOffsetLeft((left) => { |
429 |
| - return keepInHorizontalRange(left); |
430 |
| - }); |
| 434 | + const newOffsetLeft = keepInHorizontalRange(offsetLeft); |
| 435 | + setOffsetLeft(newOffsetLeft); |
| 436 | + triggerScroll({ x: newOffsetLeft }); |
431 | 437 | }
|
432 | 438 | }, [size.width, scrollWidth]);
|
433 | 439 |
|
|
0 commit comments