1.0.3 • Published 6 years ago

react-native-waterfall-layout v1.0.3

Weekly downloads
3
License
MIT
Repository
github
Last release
6 years ago

react-native-waterfall-layout

基于react-native官方组件封装的瀑布流组件

Preview

iOS

iOS

Android

Android

Getting started

1.安装

$ npm i react-native-waterfall-layout --save

2.导入

import Waterfall from 'react-native-waterfall-layout';

Properties

PropDefaultTypeDescription
columns2Number瀑布流的列数
space10Number瀑布流每列之间的间隔
renderItenullFunction用于自定义瀑布流中每一项的内容
keyExtractornullFunction为给定的item生成一个不重复的key。若不指定此函数,则默认抽取item.key作为key值。若item.key也不存在,则使用数组下标index
refreshtrueBoolean是否启用下拉刷新
refreshing(done) =>{}Function下拉刷新触发该函数,接收一个done函数用于结束刷新
refreshConfObject下拉刷新参数,配置详见RefreshControl
infinitetrueBoolean是否启用滚动加载
infiniting(done) => {}Function滚动到列表底部触发该函数,接收参数同refreshing
hasMoretrueBoolean设置为false滚动到列表底部后将不触发infiniting
renderInfiniteFunction用于自定义滚动加载组件及样式,接收一个loading用于判断是否正在加载

Methods

addItems

添加Items到瀑布流中,其中Item的高度自动计算出来,将Item添加到最矮的列中,所以会导致Items依次渲染。

this.refs.waterfall.addItems([

    {name: 'Item1'}, 

    {name: 'Item2'}

])
addItemWithHeight

添加 items 到瀑布流组件中,item的高度也将自动确定,但需要在每个item对象的数据中添加height属性,该属性不是item渲染后的实际高度,而是作为item分配列的算法参考值。和addItems不一样的是,是批量渲染的

this.refs.waterfall.addItemsWithHeight([

      {name:"Item1", height: 210 },

      {name:"Item2", height: 150 }

]);
clear

清除瀑布流中的所有项

this.refs.waterfall.clear();

Example

点击Demo查看