React Native FlatList的使用

FlatList的使用

  • 高性能的简单列表组件,支持下面这些常用的功能:
  • 完全跨平台。
  • 支持水平布局模式。
  • 行组件显示或隐藏时可配置回调事件。
  • 支持单独的头部组件。
  • 支持单独的尾部组件。
  • 支持自定义行间分隔线。
  • 支持下拉刷新。
  • 支持上拉加载。
  • 支持跳转到指定行(ScrollToIndex)。

如果需要分组/类/区(section),请使用<SectionList> 

建议以后尽量少使用ListView,毕竟性能不如FlatList

使用方便简单,如下:

import React, { Component } from 'react'
import {
    View,
    Image,
    Dimensions,
    ScrollView,
    Text,
    StyleSheet,
    TouchableOpacity,
    Button,
    FlatList,
    ActivityIndicator,
    RefreshControl,
}from 'react-native'

var flatListData = [{
        key: 'a',
        text: '444'
    },{
        key: 'b',
        text: '333'
    },{
        key: 'c',
        text: '2222'
    },{
        key: 'd',
        text: '111'
    }];

class DetailePageextends Component {

     constructor(props) {
        super(props);

        this.state = {

        };
    }

    render() {
        const { params } = this.props.navigation.state;
        return (

            <View style={styles.container}>

                <FlatList
                    style={styles.flatListStyle}
                    data={flatListData}
                    ListHeaderComponent={this.ListHeaderComponent.bind(this)}
                    renderItem={this.renderItem.bind(this)}
                    keyExtractor={this._keyExtractor}
                    refreshControl={
                        <RefreshControl
                            refreshing={false}
                        />
                    }
                />      
            </View>

        )
    }


  //此函数用于为给定的item生成一个不重复的key
    _keyExtractor = (item, index) => item.key;

    componentDidMount() {

    }

    //列表的头部
    ListHeaderComponent() {
        return (
            <DetailsHeadItem titleName='学习' unitName='111'/> 
        )
    }

    //列表的每一行
    renderItem({item,index}) {
        return (
            <TouchableOpacity key={index} activeOpacity={1} onPress={this.clickItem.bind(this,item,index)}>
                <DetaileRowItem  /> 
            </TouchableOpacity>
        )
    }
    //绘制列表的分割线
    renderItemSeparator(){

    }

    //点击列表点击每一行
    clickItem(item,index) {
        alert(index)
    }

}

export default DetailePage
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值