Git Product home page Git Product logo

virtual-list's Introduction

rc-virtual-list

React Virtual List Component which worked with animation.

NPM version dumi build status Test coverage node version npm download

Online Preview

https://virtual-list-react-component.vercel.app/

Development

npm install
npm start
open http://localhost:9001/

Feature

  • Support react.js
  • Support animation
  • Support IE11+

Install

rc-virtual-list

Usage

import List from 'rc-virtual-list';

<List data={[0, 1, 2]} height={200} itemHeight={30} itemKey="id">
  {index => <div>{index}</div>}
</List>;

API

List

Prop Description Type Default
children Render props of item (item, index, props) => ReactElement -
component Customize List dom element string | Component div
data Data list Array -
disabled Disable scroll check. Usually used on animation control boolean false
height List height number -
itemHeight Item minium height number -
itemKey Match key with item string -
styles style { horizontalScrollBar?: React.CSSProperties; horizontalScrollBarThumb?: React.CSSProperties; verticalScrollBar?: React.CSSProperties; verticalScrollBarThumb?: React.CSSProperties; } -

children provides additional props argument to support IE 11 scroll shaking. It will set style to visibility: hidden when measuring. You can ignore this if no requirement on IE.

virtual-list's People

Contributors

afc163 avatar boyyangzai avatar deepanchor avatar dunqing avatar gugods avatar jsomariano avatar jueinin avatar lgtm-com[bot] avatar linxianxi avatar lzy2014love avatar mynane avatar namewjp avatar shaleen-25 avatar thinkasany avatar vagusx avatar xifeiwu avatar xrkffgg avatar yoyo837 avatar zombiej avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

virtual-list's Issues

List.js "Not find index item. Please report this since it is a bug."

I recently installed https://github.com/ukrbublik/react-awesome-query-builder/, which is using https://github.com/ant-design/ant-design/ and one of those 2 is using your rc-virtual-list. Can you give me more insight into this "Not find index item." Is this related to the list being removed? 28c069d

Any info you can provide would be helpful. Thanks.

Here is my stack trace if it helps. Sorry there are no filenames.

Not find index item. Please report this since it is a bug.
at List
at OptionList
at div
at div
at PopupInner
at Align
at CSSMotion
at div
at Popup
at Portal
at Trigger
at SelectTrigger
at div
at Select
at Select
at Select
at FieldSelect
at Field
at div
at Col
at FieldWrapper
at div
at Rule
at div
at Draggable
at div
at RuleContainer
at ConnectedRuleContainer
at Item
at div
at Group
at div
at Draggable
at div
at GroupContainer
at ConnectedGroupContainer
at Item
at Builder
at SortableContainer
at ConnectedSortableContainer
at div
at div
at Query
at ConnectedQuery
at Provider
at LocaleProvider
at SizeContextProvider
at LocaleReceiver
at ConfigProvider
at Provider
at renderProvider
at QueryContainer
at div
at PeopleQueryBuilder
at App

server render is not support?

Warning: useLayoutEffect does nothing on the server, because its effect cannot be encoded into the server renderer's output format. This will lead to a mismatch between the initial, non-hydrated UI and the intended UI. To avoid this, useLayoutEffect should only be used in components that render exclusively on the client. See https://reactjs.org/link/uselayouteffect-ssr for common fixes.

image

Cannot read property 'removeEventListener' of null

This line of useMobileTouchMove.ts requires a null check on listRef.current:

      listRef.current.removeEventListener('touchstart', onTouchStart);

When a Select component in the latest ant design v4.6.5 is unmounted (ie. removed from the DOM), we get the following exception:

scheduler.development.js?034b:171 Uncaught TypeError: Cannot read property 'removeEventListener' of null
    at eval (useMobileTouchMove.js?684c:64)
    at HTMLUnknownElement.callCallback (react-dom.development.js?4b4a:3946)
    at Object.invokeGuardedCallbackDev (react-dom.development.js?4b4a:3995)
    at invokeGuardedCallback (react-dom.development.js?4b4a:4057)
    at safelyCallDestroy (react-dom.development.js?4b4a:20501)
    at commitHookEffectListUnmount2 (react-dom.development.js?4b4a:20634)
    at commitPassiveUnmount (react-dom.development.js?4b4a:21705)
    at flushPassiveUnmountEffectsInsideOfDeletedTree (react-dom.development.js?4b4a:23600)
    at flushPassiveUnmountEffectsInsideOfDeletedTree (react-dom.development.js?4b4a:23593)
    at flushPassiveUnmountEffectsInsideOfDeletedTree (react-dom.development

overscanRowCount - Number of rows to render above/below the visible bounds of the list. This can help reduce flickering during scrolling on certain browsers/devices.

I have a list of chat messages. The message height depends on the content.

My code is below. And everything seems to work well, but there is one moment, I can’t find the "overscanRowCount" property. Number of rows to render above/below the visible bounds of the list. This can help reduce flickering during scrolling on certain browsers/devices.

Can you do something about the flicker?

const Message = ({ i }: any, ref: any) => {
    return (
        <div
            ref={ref}
            style={{
                border: "1px solid gray",
            }}
        >
            <Avatar />
            message {i}
            // Dynamic height by content
            {i % 2 ? <div style={{ height: 100 }} /> : null}
        </div>
    );
};
const ForwardMessage = React.forwardRef(Message);

const Chat = () => {
      const listRef = React.useRef<any>(null);
      const size = useSize();
  
      // Infinite scroll
      const onScroll = (e: any) => {
          if (e.target.scrollHeight - e.target.scrollTop === size?.height) {
              appendData();
          }
      };
    
        <VirtualList
            ref={listRef}
            data={data}
            height={size?.height}
            itemHeight={30}
            itemKey="email"
            onScroll={onScroll}
        >
            {(item: any, i: any) => <ForwardMessage i={i} {...item} />}
        </VirtualList>
  }

Can not drag scrollBar when scroll stopped!

Navigator: chrome 92.0.4515.131 (x86_64)
System: Mac OS Big Sur 11.5 (20G71)

How to reproduction: Chrome's setting: close Hardware Acceleration !important
Now: Can not hover to drag scrollBar when scroll stopped; Can hover to drag when scrolling;
Expect: Can hover to drag scrollBar when scroll stopped; Or hide scrollBar when scroll stopped
Reproduction link: https://rc-virtual-list.react-component.vercel.app/?selectedKind=rc-virtual-list&selectedStory=basic&full=0&addons=1&stories=1&panelRight=0&addonPanel=storybook%2Factions%2Factions-panel

如何复现:关闭 chrome 设置里的“硬件加速”
现状:不滚动时不能拖动滚动条;滚动时能拖动滚动条
希望:不滚动时能正常拖动滚动条;或者不滚动时隐藏滚动条
复现地址: https://rc-virtual-list.react-component.vercel.app/?selectedKind=rc-virtual-list&selectedStory=basic&full=0&addons=1&stories=1&panelRight=0&addonPanel=storybook%2Factions%2Factions-panel

rc-virtual-list 3.10.0 problems with the last update

#13 8.176 ./node_modules/rc-virtual-list/lib/List.d.ts:5:15
#13 8.176 Type error: ',' expected.
#13 8.176
#13 8.176   3 | import type { ScrollBarDirectionType } from './ScrollBar';
#13 8.176   4 | import type { RenderFunc, ExtraRenderInfo } from './interface';
#13 8.176 > 5 | import { type ScrollPos, type ScrollTarget } from './hooks/useScrollTo';
#13 8.176     |               ^
#13 8.176   6 | export interface ScrollInfo {
#13 8.176   7 |     x: number;
#13 8.176   8 |     y: number;
#13 8.204 npm notice

Hello, today after the update I've been suffering from this problem only when the application builds, I don't use the lib directly as it depended on antd if I'm not mistaken. Does anyone know how to fix?

rc-util依赖版本有误

rc-virtual-list >=3.4.3下src/List使用rc-util的useLayoutEffect替换react默认钩子,该方法是rc-util >=5.15.0版本加入的。但rc-virtual-list 依赖的rc-util版本为"rc-util": "^5.0.7",若安装的rc-util低于5.15.0则会导致打包错误

got error "Cannot read property removeEventListener of null"

Hi! 👋

Firstly, thanks for your work on this project! 🙂

Today I used patch-package to patch [email protected] for the project I'm working on.

Here is the diff that solved my problem:

diff --git a/node_modules/rc-virtual-list/es/List.js b/node_modules/rc-virtual-list/es/List.js
index 6346b0d..47c327f 100644
--- a/node_modules/rc-virtual-list/es/List.js
+++ b/node_modules/rc-virtual-list/es/List.js
@@ -284,9 +284,11 @@ export function RawList(props, ref) {
     componentRef.current.addEventListener('DOMMouseScroll', onFireFoxScroll);
     componentRef.current.addEventListener('MozMousePixelScroll', onMozMousePixelScroll);
     return function () {
-      componentRef.current.removeEventListener('wheel', onRawWheel);
-      componentRef.current.removeEventListener('DOMMouseScroll', onFireFoxScroll);
-      componentRef.current.removeEventListener('MozMousePixelScroll', onMozMousePixelScroll);
+      if (componentRef.current) {
+        componentRef.current.removeEventListener('wheel', onRawWheel);
+        componentRef.current.removeEventListener('DOMMouseScroll', onFireFoxScroll);
+        componentRef.current.removeEventListener('MozMousePixelScroll', onMozMousePixelScroll);
+      }
     };
   }, [useVirtual]); // ================================= Ref ==================================
 
diff --git a/node_modules/rc-virtual-list/es/hooks/useMobileTouchMove.js b/node_modules/rc-virtual-list/es/hooks/useMobileTouchMove.js
index 0fdb2dd..dc4be2c 100644
--- a/node_modules/rc-virtual-list/es/hooks/useMobileTouchMove.js
+++ b/node_modules/rc-virtual-list/es/hooks/useMobileTouchMove.js
@@ -63,7 +63,9 @@ export default function useMobileTouchMove(inVirtual, listRef, callback) {
     }
 
     return function () {
-      listRef.current.removeEventListener('touchstart', onTouchStart);
+       if (listRef.current) {
+        listRef.current.removeEventListener('touchstart', onTouchStart);
+      }
       cleanUpEvents();
       clearInterval(intervalRef.current);
     };
diff --git a/node_modules/rc-virtual-list/lib/List.js b/node_modules/rc-virtual-list/lib/List.js
index 9d2d517..b6c727b 100644
--- a/node_modules/rc-virtual-list/lib/List.js
+++ b/node_modules/rc-virtual-list/lib/List.js
@@ -311,9 +311,11 @@ function RawList(props, ref) {
     componentRef.current.addEventListener('DOMMouseScroll', onFireFoxScroll);
     componentRef.current.addEventListener('MozMousePixelScroll', onMozMousePixelScroll);
     return function () {
-      componentRef.current.removeEventListener('wheel', onRawWheel);
-      componentRef.current.removeEventListener('DOMMouseScroll', onFireFoxScroll);
-      componentRef.current.removeEventListener('MozMousePixelScroll', onMozMousePixelScroll);
+      if (componentRef.current) {
+        componentRef.current.removeEventListener('wheel', onRawWheel);
+        componentRef.current.removeEventListener('DOMMouseScroll', onFireFoxScroll);
+        componentRef.current.removeEventListener('MozMousePixelScroll', onMozMousePixelScroll);
+      }
     };
   }, [useVirtual]); // ================================= Ref ==================================
 
diff --git a/node_modules/rc-virtual-list/lib/hooks/useMobileTouchMove.js b/node_modules/rc-virtual-list/lib/hooks/useMobileTouchMove.js
index a809897..7c20443 100644
--- a/node_modules/rc-virtual-list/lib/hooks/useMobileTouchMove.js
+++ b/node_modules/rc-virtual-list/lib/hooks/useMobileTouchMove.js
@@ -77,7 +77,9 @@ function useMobileTouchMove(inVirtual, listRef, callback) {
     }
 
     return function () {
-      listRef.current.removeEventListener('touchstart', onTouchStart);
+      if (listRef.current) {
+        listRef.current.removeEventListener('touchstart', onTouchStart);
+      }
       cleanUpEvents();
       clearInterval(intervalRef.current);
     };

This issue body was partially generated by patch-package.

增加一个autoHeight的例子,就是不限制高度,滚动使用浏览器的滚动条,信息流模式的网站,如果设置了固定高度,浏览器内也有滚动条了

如题,现在新版的新浪微博用的是 vue,他也用了 virtual-list 这种功能,主体内容部分不需要设置固定的高度,还是使用浏览器的滚动条,信息流区域没有自己的滚动条。

和这个功能类似:https://bvaughn.github.io/react-virtualized/#/components/WindowScroller
还有这个:https://bvaughn.github.io/react-virtualized/#/components/Masonry 不过要勾选里面的一个选项 Use WindowScroller?

为啥不直接用上在的库呢,他太大了,想要个轻量的,希望可以采纳。

Dynamic line height

Is it possible to have a dynamic line height or am I overlooking the feature?

What I would like to have:

const dynLineHeight = (row: any, index: number) => {
	if(index % 2 === 0){
		return 50;
	} else {
		return 25;
	}
}

<List data={[0, 1, 2]} height={200} itemHeight={this.dynLineHeight} itemKey="id">
  {index => <div>{index}</div>}
</List>;

React 17: Cannot read property 'removeEventListener' of null

This error is thrown "React 17: Cannot read property 'removeEventListener' of null" when using React 17, unmounting

  217 | React.useEffect(function () {
  218 |   componentRef.current.addEventListener('wheel', onRawWheel);
  219 |   return function () {
> 220 |     componentRef.current.removeEventListener('wheel', onRawWheel);
      | ^  221 |   };
  222 | }, [inVirtual]); // ================================= Ref ==================================
  223 | 

Namespace 'React' has no exported member 'JSX'

Version 3.5.1 is throwing a type error from inside node_modules:

../../common/temp/node_modules/.pnpm/[email protected]_sfoxds7t5ydpegc3knd667wn6m/node_modules/rc-virtual-list/lib/List.d.ts:38:89 - error TS2694: Namespace 'React' has no exported member 'JSX'.

38 export declare function RawList<T>(props: ListProps<T>, ref: React.Ref<ListRef>): React.JSX.Element;
                                                                                           ~~~

../../common/temp/node_modules/.pnpm/[email protected]_sfoxds7t5ydpegc3knd667wn6m/node_modules/rc-virtual-list/lib/ScrollBar.d.ts:42:21 - error TS2694: Namespace 'React' has no exported member 'JSX'.

42     render(): React.JSX.Element;
                       ~~~


Found 2 errors in 2 files.

Errors  Files
     1  ../../common/temp/node_modules/.pnpm/[email protected]_sfoxds7t5ydpegc3knd667wn6m/node_modules/rc-virtual-list/lib/List.d.ts:38
     1  ../../common/temp/node_modules/.pnpm/[email protected]_sfoxds7t5ydpegc3knd667wn6m/node_modules/rc-virtual-list/lib/ScrollBar.d.ts:42

虚拟列表中途加入数据出现滚动抖动的bug

场景:上滑加载历史评论(每条都是两行显示)与原来的评论(每条都是一行显示)合并渲染时(合并操作为原来的列表内容向前追加历史评论),新加入的历史评论内容滚动时出现抖动情况,怀疑时新加入的评论itemHeight和原来不统一导致的。

Support horizontal scrollbar if "nowrap" enabled for item's labels

We would like to utilize the nowrap for our item's label.
Actually, we are using the Tree component from Ant, with virtual scroll enabled.

As a workaround we managed to get the horizontal scrollbar enabled (adding css styles ourself), but this actually overlaps the last item in list.

You see any way to get that horizontal scroll enabled by virtual-list component natively?

Be able to choose whether to hide scrollbar after delay or not

By default, scrollbar disappears after 2 seconds.

delayHidden = () => {
    clearTimeout(this.visibleTimeout);

    this.setState({ visible: true });
    this.visibleTimeout = setTimeout(() => {
      this.setState({ visible: false });
    }, 2000);
  };

It'd be helpful to be able to choose the delay or not. From user experience side, this causes some confusion

滚动指定的行

背景

在操作的过程中,想回到之前操作的行

目的

列表滚动到指定的行

Enhancement: reduce the inline style

Intro

I wanna change the background of thumb, but this style is an inline style so that I can't rewrite it.

<div
ref={this.thumbRef}
className={classNames(`${prefixCls}-scrollbar-thumb`, {
[`${prefixCls}-scrollbar-thumb-moving`]: dragging,
})}
style={{
width: '100%',
height: spinHeight,
top,
left: 0,
position: 'absolute',
background: 'rgba(0, 0, 0, 0.5)',
borderRadius: 99,
cursor: 'pointer',
userSelect: 'none',
}}
onMouseDown={this.onMouseDown}
/>
</div>

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.