Skip to content

chore: use @rc-component/resize-observer #302

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ lib/
~*
yarn.lock
package-lock.json
!tests/__mocks__/rc-util/lib
pnpm-lock.yaml
!tests/__mocks__/@rc-component/util/lib
bun.lockb

# umi
Expand Down
12 changes: 6 additions & 6 deletions examples/animate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import * as React from 'react';
import CSSMotion from 'rc-animate/lib/CSSMotion';
import classNames from 'classnames';
import List, { ListRef } from '../src/List';
import useLayoutEffect from 'rc-util/lib/hooks/useLayoutEffect';
import useLayoutEffect from '@rc-component/util/lib/hooks/useLayoutEffect';
import './animate.less';

let uuid = 0;
Expand Down Expand Up @@ -74,7 +74,7 @@ const MyItem: React.ForwardRefRenderFunction<any, MyItemProps> = (
motionName="motion"
motionAppear={motionAppear}
onAppearStart={getCollapsedHeight}
onAppearActive={node => {
onAppearActive={(node) => {
motionRef.current = true;
return getMaxHeight(node);
}}
Expand Down Expand Up @@ -135,7 +135,7 @@ const Demo = () => {
const [animating, setAnimating] = React.useState(false);
const [insertIndex, setInsertIndex] = React.useState<number>();

const listRef = React.useRef<ListRef>();
const listRef = React.useRef<ListRef>(null);

const onClose = (id: string) => {
setCloseMap({
Expand All @@ -145,7 +145,7 @@ const Demo = () => {
};

const onLeave = (id: string) => {
const newData = data.filter(item => item.id !== id);
const newData = data.filter((item) => item.id !== id);
setData(newData);
};

Expand All @@ -159,14 +159,14 @@ const Demo = () => {
}

const onInsertBefore = (id: string) => {
const index = data.findIndex(item => item.id === id);
const index = data.findIndex((item) => item.id === id);
const newData = [...data.slice(0, index), genItem(), ...data.slice(index)];
setInsertIndex(index);
setData(newData);
lockForAnimation();
};
const onInsertAfter = (id: string) => {
const index = data.findIndex(item => item.id === id) + 1;
const index = data.findIndex((item) => item.id === id) + 1;
const newData = [...data.slice(0, index), genItem(), ...data.slice(index)];
setInsertIndex(index);
setData(newData);
Expand Down
28 changes: 14 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rc-virtual-list",
"version": "3.18.1",
"name": "@rc-component/virtual-list",
"version": "1.0.0",
"description": "React Virtual List Component",
"engines": {
"node": ">=8.x"
Expand Down Expand Up @@ -36,9 +36,11 @@
"test": "rc-test",
"now-build": "npm run build"
},
"peerDependencies": {
"react": ">=16.9.0",
"react-dom": ">=16.9.0"
"dependencies": {
"@babel/runtime": "^7.20.0",
"@rc-component/resize-observer": "^1.0.0",
"@rc-component/util": "^1.2.0",
"classnames": "^2.2.6"
},
"devDependencies": {
"@rc-component/father-plugin": "^1.0.2",
Expand All @@ -47,8 +49,8 @@
"@types/classnames": "^2.2.10",
"@types/enzyme": "^3.10.5",
"@types/jest": "^25.1.3",
"@types/react": "^18.0.8",
"@types/react-dom": "^18.0.3",
"@types/react": "^19.0.8",
"@types/react-dom": "^19.0.3",
"@types/warning": "^3.0.0",
"cheerio": "1.0.0-rc.12",
"cross-env": "^5.2.0",
Expand All @@ -63,14 +65,12 @@
"np": "^5.0.3",
"rc-animate": "^2.9.1",
"rc-test": "^7.0.15",
"react": "16.14.0",
"react-dom": "16.14.0",
"react": "^19.0.0",
"react-dom": "^19.0.0",
"typescript": "^5.0.0"
},
"dependencies": {
"@babel/runtime": "^7.20.0",
"classnames": "^2.2.6",
"rc-resize-observer": "^1.0.0",
"rc-util": "^5.36.0"
"peerDependencies": {
"react": ">=16.9.0",
"react-dom": ">=16.9.0"
}
}
6 changes: 4 additions & 2 deletions src/Filler.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react';
import ResizeObserver from 'rc-resize-observer';
import ResizeObserver from '@rc-component/resize-observer';
import classNames from 'classnames';

export type InnerProps = Pick<React.HTMLAttributes<HTMLDivElement>, 'role' | 'id'>;
Expand Down Expand Up @@ -95,6 +95,8 @@ const Filler = React.forwardRef(
},
);

Filler.displayName = 'Filler';
if (process.env.NODE_ENV !== 'production') {
Filler.displayName = 'Filler';
}

export default Filler;
30 changes: 15 additions & 15 deletions src/List.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import classNames from 'classnames';
import type { ResizeObserverProps } from 'rc-resize-observer';
import ResizeObserver from 'rc-resize-observer';
import { useEvent } from 'rc-util';
import useLayoutEffect from 'rc-util/lib/hooks/useLayoutEffect';
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 * as React from 'react';
import { useRef, useState } from 'react';
import { flushSync } from 'react-dom';
Expand Down Expand Up @@ -148,9 +148,9 @@ export function RawList<T>(props: ListProps<T>, ref: React.Ref<ListRef>) {

const mergedClassName = classNames(prefixCls, { [`${prefixCls}-rtl`]: isRTL }, className);
const mergedData = data || EMPTY_DATA;
const componentRef = useRef<HTMLDivElement>();
const fillerInnerRef = useRef<HTMLDivElement>();
const containerRef = useRef<HTMLDivElement>();
const componentRef = useRef<HTMLDivElement>(null);
const fillerInnerRef = useRef<HTMLDivElement>(null);
const containerRef = useRef<HTMLDivElement>(null);

// =============================== Item Key ===============================

Expand Down Expand Up @@ -190,7 +190,7 @@ export function RawList<T>(props: ListProps<T>, ref: React.Ref<ListRef>) {
// Put ref here since the range is generate by follow
const rangeRef = useRef({ start: 0, end: mergedData.length });

const diffItemRef = useRef<T>();
const diffItemRef = useRef<T>(null);
const [diffItem] = useDiffItem(mergedData, getKey);
diffItemRef.current = diffItem;

Expand Down Expand Up @@ -303,8 +303,8 @@ export function RawList<T>(props: ListProps<T>, ref: React.Ref<ListRef>) {
};

// Hack on scrollbar to enable flash call
const verticalScrollBarRef = useRef<ScrollBarRef>();
const horizontalScrollBarRef = useRef<ScrollBarRef>();
const verticalScrollBarRef = useRef<ScrollBarRef>(null);
const horizontalScrollBarRef = useRef<ScrollBarRef>(null);

const horizontalScrollBarSpinSize = React.useMemo(
() => getSpinSize(size.width, scrollWidth),
Expand Down Expand Up @@ -587,17 +587,15 @@ export function RawList<T>(props: ListProps<T>, ref: React.Ref<ListRef>) {
}

const containerProps: React.HTMLAttributes<HTMLDivElement> = {};

if (isRTL) {
containerProps.dir = 'rtl';
}

return (
<div
ref={containerRef}
style={{
...style,
position: 'relative',
}}
style={{ ...style, position: 'relative' }}
className={mergedClassName}
{...containerProps}
{...restProps}
Expand Down Expand Up @@ -669,7 +667,9 @@ export function RawList<T>(props: ListProps<T>, ref: React.Ref<ListRef>) {

const List = React.forwardRef<ListRef, ListProps<any>>(RawList);

List.displayName = 'List';
if (process.env.NODE_ENV !== 'production') {
List.displayName = 'List';
}

export default List as <Item = any>(
props: ListProps<Item> & { ref?: React.Ref<ListRef> },
Expand Down
12 changes: 6 additions & 6 deletions src/ScrollBar.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import classNames from 'classnames';
import raf from 'rc-util/lib/raf';
import raf from '@rc-component/util/lib/raf';
import * as React from 'react';
import { getPageXY } from './hooks/useScrollDrag';

Expand Down Expand Up @@ -49,12 +49,12 @@ const ScrollBar = React.forwardRef<ScrollBarRef, ScrollBarProps>((props, ref) =>
const isLTR = !rtl;

// ========================= Refs =========================
const scrollbarRef = React.useRef<HTMLDivElement>();
const thumbRef = React.useRef<HTMLDivElement>();
const scrollbarRef = React.useRef<HTMLDivElement>(null);
const thumbRef = React.useRef<HTMLDivElement>(null);

// ======================= Visible ========================
const [visible, setVisible] = React.useState(showScrollBar);
const visibleTimeoutRef = React.useRef<ReturnType<typeof setTimeout>>();
const visibleTimeoutRef = React.useRef<ReturnType<typeof setTimeout>>(null);

const delayHidden = () => {
if (showScrollBar === true || showScrollBar === false) return;
Expand Down Expand Up @@ -120,9 +120,9 @@ const ScrollBar = React.forwardRef<ScrollBarRef, ScrollBarProps>((props, ref) =>
}, []);

// Pass to effect
const enableScrollRangeRef = React.useRef<number>();
const enableScrollRangeRef = React.useRef<number>(null);
enableScrollRangeRef.current = enableScrollRange;
const enableOffsetRangeRef = React.useRef<number>();
const enableOffsetRangeRef = React.useRef<number>(null);
enableOffsetRangeRef.current = enableOffsetRange;

React.useEffect(() => {
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-util/lib/raf';
import raf from '@rc-component/util/lib/raf';
import { useRef } from 'react';
import isFF from '../utils/isFirefox';
import useOriginScroll from './useOriginScroll';
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useHeights.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import findDOMNode from 'rc-util/lib/Dom/findDOMNode';
import findDOMNode from '@rc-component/util/lib/Dom/findDOMNode';
import * as React from 'react';
import { useEffect, useRef } from 'react';
import type { GetKey } from '../interface';
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-util/lib/hooks/useLayoutEffect';
import useLayoutEffect from '@rc-component/util/lib/hooks/useLayoutEffect';
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-util/lib/raf';
import raf from '@rc-component/util/lib/raf';
import * as React from 'react';

function smoothScrollOffset(offset: number) {
Expand Down
8 changes: 4 additions & 4 deletions src/hooks/useScrollTo.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/* eslint-disable no-param-reassign */
import * as React from 'react';
import raf from 'rc-util/lib/raf';
import raf from '@rc-component/util/lib/raf';
import type { GetKey } from '../interface';
import type CacheMap from '../utils/CacheMap';
import useLayoutEffect from 'rc-util/lib/hooks/useLayoutEffect';
import { warning } from 'rc-util';
import useLayoutEffect from '@rc-component/util/lib/hooks/useLayoutEffect';
import { warning } from '@rc-component/util';

const MAX_TIMES = 10;

Expand Down Expand Up @@ -37,7 +37,7 @@ export default function useScrollTo<T>(
syncScrollTop: (newTop: number) => void,
triggerFlash: () => void,
): (arg: number | ScrollTarget) => void {
const scrollRef = React.useRef<number>();
const scrollRef = React.useRef<number>(null);

const [syncState, setSyncState] = React.useState<{
times: number;
Expand Down
4 changes: 3 additions & 1 deletion src/mock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ const List = React.forwardRef((props: ListProps<any>, ref: React.Ref<ListRef>) =
props: React.PropsWithChildren<ListProps<Item>> & { ref?: React.Ref<ListRef> },
) => React.ReactElement;

(List as any).displayName = 'List';
if (process.env.NODE_ENV !== 'production') {
(List as any).displayName = 'List';
}

export default List;
4 changes: 2 additions & 2 deletions tests/scroll.test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import '@testing-library/jest-dom';
import { act, createEvent, fireEvent, render } from '@testing-library/react';
import { mount } from 'enzyme';
import { _rs as onLibResize } from 'rc-resize-observer/lib/utils/observerUtil';
import { resetWarned } from 'rc-util/lib/warning';
import { _rs as onLibResize } from '@rc-component/resize-observer/lib/utils/observerUtil';
import { resetWarned } from '@rc-component/util/lib/warning';
import React from 'react';
import List from '../src';
import { spyElementPrototypes } from './utils/domHook';
Expand Down
4 changes: 2 additions & 2 deletions tests/scrollWidth.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import '@testing-library/jest-dom';
import { act, fireEvent, render } from '@testing-library/react';
import { _rs as onLibResize } from 'rc-resize-observer/lib/utils/observerUtil';
import { spyElementPrototypes } from 'rc-util/lib/test/domHook';
import { _rs as onLibResize } from '@rc-component/resize-observer/lib/utils/observerUtil';
import { spyElementPrototypes } from '@rc-component/util/lib/test/domHook';
import React from 'react';
import type { ListRef } from '../src';
import List, { type ListProps } from '../src';
Expand Down
Loading