Longlist

基于 FlatList 的长列表组件,支持下拉刷新,上拉加载更多。

Install

  1. npm install beeshell

Usage

  1. import { Longlist } from 'beeshell';

Examples

image

Code

  1. import { Longlist } from 'beeshell';
  2. class App extends React.Component {
  3. componentDidMount() {
  4. this.refreshState(1);
  5. }
  6. refreshState = (pageNo) => {
  7. const params = {
  8. pageNo: pageNo || 1,
  9. pagesize: this.state.pagesize,
  10. id: '123456',
  11. };
  12. return this.getList(params).then((resData) => {
  13. const { data } = resData;
  14. const list = data.map((item) => {
  15. return {
  16. ...item,
  17. label: `${item.label}--pageNo: ${params.pageNo}`,
  18. };
  19. });
  20. this.setState({
  21. list: (pageNo == 1 ? [] : this.state.list).concat(list),
  22. });
  23. });
  24. }
  25. render() {
  26. const { list } = this.state;
  27. return (
  28. <Longlist
  29. data={list}
  30. renderItem={({item, index}) => {
  31. return (<Text>{item.label}</Text>);
  32. }}
  33. hasRefreshControl={true}
  34. onEndReached={this.refreshState}
  35. onRefresh={this.refreshState}
  36. />
  37. );
  38. }
  39. }

Props

Name Type Required Default Description
data Array true [] 数据源
renderItem Function true null 渲染内容
hasRefreshControl Boolean false true 是否可以下拉刷新
onEndReached Function false null 滚动到底部回调
onRefresh Function false null 下拉刷新回调