0.1.1 • Published 4 years ago

react-x-virtual v0.1.1

Weekly downloads
1
License
MIT
Repository
-
Last release
4 years ago

如何使用?

npm i react-x-virtual
import React from 'react';
import VirtualList from 'react-x-virtual';

const {
  Header: VirtualHeader,
  Footer: VirtualFooter,
  Section: VirtualSection,
} = VirtualList;

// JSX
<VirtualList {...mixinProps} ref={vlistRef} scrollX width={600} height={200}>
  <VirtualSection itemCount={2050}>
    <VirtualHeader width={100}>
      <div className="ContentTextBox">
        <p>First Header</p>
      </div>
    </VirtualHeader>
    <Row>First Section Row</Row>
    <VirtualFooter width={120}>
      <ContentTextBox tag="section-1" />
    </VirtualFooter>
  </VirtualSection>

  <VirtualSection itemCount={1500}>
    <VirtualHeader width={150}>
      <ContentTextBox tag="section-2" />
    </VirtualHeader>
    <Row>Second Section Row</Row>
    <VirtualFooter width={100}>
      <ContentTextBox tag="section-2" />
    </VirtualFooter>
  </VirtualSection>
</VirtualList>;

API

type TypeItemSizeHandler = Array<number> | Array<(idx: number):number>
type TypeSize = number | string
type TypeAlignment = 'auto' | 'start' | 'center' | 'end'
type TypeAlignTo = 'none' | 'top' | 'bottom'

\ API

属性类型默认值是否必填说明
itemCountnumber0长列表有多少个 Cell
scrollXbooleanfalse设置为横向滚动
scrollYbooleantrue设置为竖向滚动
initialScrollIndexnumber0在列表初始化时即可指定显示的 index,避免初始化后再通过 scrollTo 系列方法产生的闪动
onScrollEventHandler滚动时触发
scrollEventThrottlenumber10指定滑动事件的回调频率,传入数值指定了多少毫秒(ms)组件会调用一次 scroll 回调事件
onStartScrollEventHandler开始滚动时触发
onEndScrollEventHandler结束滚动时触发
upperThresholdnumber50距顶部/左边多远时(单位 px),触发 scrolltoupper 事件
onScrollToUpperEventHandler滚动到顶部/左边
lowerThresholdnumber50距底部/右边多远时(单位 px),触发 scrolltolower 事件
onScrollToLowerEventHandler滚动到底部/右边
initialRowsnumber5在异步长列表实现中, 首次渲染多少行数据. 需要能覆盖显示区域
scrollTonumber滑动的距离
widthTypeSize容器宽度,当 scrollX 时必填
heightTypeSize容器高度,当 scrollY 时必填
itemSizeTypeItemSizeHandler50, ...列表子项高度配置
estimatedItemSizenumber50预估列表子项尺寸
scrollToAlignmentTypeAlignment'auto'滚动对齐策略

\ API

属性类型默认值是否必填说明
widthTypeSizeHeader 宽度,当 scrollX 时必填
heightTypeSizeHeader 高度,当 scrollY 时必填

\ API

属性类型默认值是否必填说明
widthTypeSizeFooter 宽度,当 scrollX 时必填
heightTypeSizeFooter 高度,当 scrollY 时必填

\ API

属性类型默认值是否必填说明
itemCountnumber0Section 有多少个 Cell

Row/Column API

属性类型默认值是否必填说明
onNodeAppearEventHandler节点可见时的回调

ScrollToPosition

虚拟列表抛掷动画,调用方式如下:

virtualListRef.current.scrollToPosition(/* params */);

Params 参数示意:

属性类型默认值是否必填说明
positionnumber取值范围:0 ~ itemCount。虚拟子节点 index (在包含多个 section 的情况下,不是 section 内的 itemIndex)
smoothbooleanfalse是否有平滑动画
alignToTypeAlignTo'none'滚动后目标节点的对齐方式(默认对齐/顶部对齐/底部对齐)

更多

如对实现感兴趣,可以参考我的博客:浅谈虚拟列表实现与原理分析