FlatList处理刷新加载:
【两个标志位配合onEndReached和onContentSizeChange两个方法,处理上拉加载执行多次的情况】
import React, {
PureComponent }from 'react';
import {
StyleSheet, FlatList,Text,View,ActivityIndicator} from 'react-native';
import PropTypes from 'prop-types';
import color from '../../color';
/**
* page:{ 扩展FlatList组件,提供出刷新,header和footer }
* function:列表展示
*
* using sample:
*
* 1、刷新+加载:
*
* <BaseListView
* ...
* onRef={(ref)=>{ that.child = ref}}
*
* //是否开启 刷新 功能
* isOpenRefreshing={true}
* onRefreshPulling={()=>{
* setTimeout(()=>{
* //调用子view的方法
* that.child.setRefreshingFinish();
* },6000)
* }}
*
* //是否开启 上拉加载 功能
* isOpenLoadMore={true}
* onLoadPulling={()=>{
* setTimeout(()=>{
* //调用子view的方法
* that.child.setLoadingFinish();
* },6000)
* }}
*
* ...
* />
*
* 2、刷新:
* //是否开启 刷新 功能
* isOpenRefreshing={true}
*
* 3、加载:
* //是否开启 上拉加载 功能
* isOpenLoadMore={true}
*
* 4、单纯的列表:
* baseListData
* listCellView
*
* 5、header:
* headerChildView
*
* 6、footer:
* footerChildView
*
* time:2021/6/18
* author:bai
*/
let that;//全局属性【用于保证this的有效区域】
export default class BaseListView extends PureComponent {
static defaultProps={
//是否打开刷新
isOpenRefreshing:false,
//是否打开加载更多
isOpenLoadMore: false,
//列表列数
numColumns: 1,
}
//提供基本属性和方法
static propTypes = {
//是否打开刷新
isOpenRefreshing:PropTypes.bool,
//是否打开加载更多
isOpenLoadMore: PropTypes.bool,
//列表列数
numColumns: PropTypes.number,
//列表数据
baseListData:PropTypes.array,
//列表item view
listCellView: PropTypes.func,
//header头部子view
headerChildView: PropTypes.element,
//footer底部子view
footerChildView: PropTypes.element,
//刷新操作(页码)
onRefreshPulling:PropTypes.func,
//加载操作(页码)
onLoadPulling:PropTypes.func,
};
constructor(props){
super(props)<