1.0.17 • Published 7 years ago

react-native-sf-flatlist v1.0.17

Weekly downloads
-
License
ISC
Repository
-
Last release
7 years ago

react-native-sf-flatlist

支持上拉下拉刷新的FlatList,解决ListEmptyComponent不能居中显示的问题,并且只在第一次数据加载后数据为空时才会显示

show show

安装

  • npm install react-native-sf-flatlist

Props

parametertyperequireddescriptiondefault
onBeginRefreshHeaderfuncno开始下拉刷新回调null
onBeginRefreshFooterfuncno开始上拉刷新回调null
onEndShouldRatenumberno上拉开始刷新的距离(0-1.0)0.2
refreshHeaderTitlestringno上拉刷新标题null
refreshHeaderColorstringno上拉刷新菊花颜色null
refreshHeaderBgColorstringno上拉刷新背景颜色(仅限Android)null
emptyComponentcomponentno空数据时显示组件null
emptyDefaultTitlestringnoemptyComponent为空时默认空数据标题'没有数据'
emptyDefaultColorstringnoemptyComponent为空时默认空数据颜色'rgba(200,200,200,1)'

Methods

MethodsParamsParam TypesdescriptionExample
beginRefreshHeadernullnull手动开始下拉刷新
endRefreshHeadernullnull结束下拉刷新(数据更新成功后调用)
endRefreshFooternullnull结束上拉刷新(数据更新成功后调用)
endRefreshNomorenullnull结束上拉刷新,没有更多数据状态,再次加载不会调用onBeginRefreshFooter(数据更新成功后调用)

例子

import React, { Component } from 'react';
import {
  Platform,
  StyleSheet,
  Text,
  View,
  Image,
    Dimensions
} from 'react-native';
import SFFlatList from "react-native-sf-flatlist"
var width = Dimensions.get('window').width;

export default class App extends Component {
  constructor(props){
    super(props);
    this.state = {
      dataSource:[

      ]
    }
  }
  componentDidMount() {
    this.refs.flat.beginRefreshHeader()

  }
  onBeginRefreshHeader = () => {
    setTimeout(()=>{
      //测试数据
      tmp = [];
      for (var i = 0; i < 15; i++){
        var data = {name:'标题_'+i,des:'描述描述'};
        tmp.push(data);
      }
      this.setState({
        dataSource:tmp
      })
      //结束下拉刷新
      this.refs.flat.endRefreshHeader()
    },1000)
  }
  onBeginRefreshFooter = () => {
    setTimeout(()=>{
      //测试数据
      tmp = [];
      for (var i = 0; i < 5; i++){
        var data = {name:'标题_'+i,des:'描述描述'};
        tmp.push(data);
      }
      this.setState({
        dataSource:this.state.dataSource.concat(tmp)
      },()=>{
        this.refs.flat.endRefreshFooter()
      })

      //结束上啦刷新

    },2000)
  }
  _renderItem = ({item}) => {
    return(
      <View style={{
        height:50
      }}>
        <Text style={{
          fontSize:20,
          color:'black'
        }}>{item.name}</Text>
      </View>
    )
  }
  emptyComponent = () => {
    return(
        <View style={{
          width:width,
          height:300,
          alignItems:'center',
          justifyContent:'center'
        }}>
          <Image style={{
            width:100,
            height:100
          }} source={require('./img/comment.png')}>

          </Image>
          <Text style={{
            color:'rgba(205,205,205,1)',
            fontSize:15,
            marginTop:20
          }}>{'还没有人评论,加油跟帖吧~'}</Text>
        </View>
    )
  }
  render() {
    return (
      <View style={styles.container}>
        <View style={{
          width:width,
          height:60,
          alignItems:'center',
          backgroundColor:'rgba(33,143,252,1)',
          justifyContent:'center'
        }}>
          <Text style={{
            fontSize:16,
            color:'white',
            marginTop:10
          }}>FlatList</Text>
        </View>
        <SFFlatList
            ref = "flat"
            onBeginRefreshHeader={this.onBeginRefreshHeader}
            onBeginRefreshFooter={this.onBeginRefreshFooter}
            emptyComponent={this.emptyComponent()}
            data={this.state.dataSource}
            renderItem={this._renderItem}
        />
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1
  },

});
1.0.17

7 years ago

1.0.16

7 years ago

1.0.15

7 years ago

1.0.14

7 years ago

1.0.13

7 years ago

1.0.12

7 years ago

1.0.11

7 years ago

1.0.10

7 years ago

1.0.9

7 years ago

1.0.8

7 years ago

1.0.7

7 years ago

1.0.6

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago