FlatList和SectionList

FlatView
ItemSeparatorComponent:分割線組件,
ListFooterComponent:結(jié)尾組件
ListHeaderComponent:頭組件
data:列表數(shù)據(jù) (必須有)
horizontal:設(shè)置為true則變?yōu)樗搅斜怼?br> numColumns:列數(shù) 組件內(nèi)元素必須是等高的,無(wú)法支持瀑布流布局
columnWrapperStyle:numColumns大于1時(shí),設(shè)置每行的樣式
getItemLayout:如果我們知道行高可以用此方法節(jié)省動(dòng)態(tài)計(jì)算行高的開(kāi)銷(xiāo)。
refreshing:是否正在加載數(shù)據(jù)
onRefresh:設(shè)置此屬性需要一個(gè)標(biāo)準(zhǔn)的 RefreshControl 控件,刷新數(shù)據(jù)
renderItem:渲染每個(gè)組件 (必須有)
onViewableItemsChanged:當(dāng)一個(gè)新的Item渲染或者隱藏 的時(shí)候調(diào)用此方法。參數(shù):info: {viewableItems: Array, changed: Array} viewableItems:當(dāng)前可見(jiàn)的Item,changed:渲染或者隱藏的Item。
scrollToEnd({params?: ?{animated?: ?boolean}}):滾動(dòng)到末尾,如果不設(shè)置getItemLayout屬性的話,可能會(huì)比較卡。
scrollToIndexparams: {animated?: ?boolean, index: number, viewPosition?: number}:滾動(dòng)到制定的位置
scrollToOffset(params: {animated?: ?boolean, offset: number}):滾動(dòng)到指定的偏移的位置。


Demo.png

渲染函數(shù)

_renderItem = (item) => {
        var txt = '第' + item.index + '個(gè)' + ' title=' + item.item.title;
        var bgColor = item.index % 2 == 0 ? 'red' : 'blue';
        return <Text style={[{flex:1,height:ITEM_HEIGHT,backgroundColor:bgColor},styles.txt]}>{txt}</Text>
    }

item.index:該數(shù)據(jù)對(duì)應(yīng)的位置,
item.item.title:數(shù)組中的內(nèi)容
SectionList:


import React, { Component } from 'react';
import {StyleSheet, Text, View, Image, TouchableOpacity,SectionList, FlatList, Alert} from 'react-native';
import Data from './Data3';
var Dimensions = require('Dimensions');
var {width} = Dimensions.get('window');
export default class Small extends Component {

    render() {
        return(
           <SectionList
               sections={Data}
               renderSectionHeader={this.RenderSectionHeader}
               renderItem={this.RenderItem}
               style={styles.ceilViewStyle}

           />
        );
    }
    RenderItem=(info)=>{
        return(
            <View style>
                <Image source={{uri:info.item.icon}}
                       style={styles.leftImageStyle}
                />
                <Text>{info.item.name}</Text>
            </View>
        );
    }
    RenderSectionHeader=(info)=>{
        return(
            <Text>{info.section.title}</Text>
        );
    }

}
const styles = StyleSheet.create({
    ceilViewStyle:{
        padding:10,
        borderBottomWidth:0.5,
        borderBottomColor:'yellow',
        flexDirection:'row',

    },
    leftImageStyle:{
        width:80,
        height:60,
        marginRight:15,
    },
    rightViewStyle:{

    },
    topTitle:{
        fontSize:20,
    },

    bottomTitleStyle:{
        width:width*0.7,
        marginTop:5
    }
})

sectionList比FlatList多一個(gè),key屬性,(info.item.屬性名),(info.section.key),用于實(shí)現(xiàn)手機(jī)通信錄。

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • FlatList的簡(jiǎn)述 簡(jiǎn)單的栗子 data里塞數(shù)據(jù),其實(shí)就是一個(gè)數(shù)組,數(shù)組里每個(gè)元素就是個(gè)字典 renderIt...
    踏云小子閱讀 2,656評(píng)論 0 3
  • 1、通過(guò)CocoaPods安裝項(xiàng)目名稱(chēng)項(xiàng)目信息 AFNetworking網(wǎng)絡(luò)請(qǐng)求組件 FMDB本地?cái)?shù)據(jù)庫(kù)組件 SD...
    陽(yáng)明AI閱讀 16,172評(píng)論 3 119
  • FlatList是一個(gè)高性能的列表組件,它是ListView組件的升級(jí)版,性能方面有了很大的提升,當(dāng)然也就建議大家...
    代碼森林中的一只貓閱讀 2,649評(píng)論 0 3
  • 【LCZ1601~羅芳萍】 初次相見(jiàn) 你柔情似水 我的那顆心啊 立刻PCR出無(wú)數(shù)愛(ài)的片斷 你的眼神 像線粒體一樣 ...
    米蘭_9076閱讀 11,868評(píng)論 0 2
  • 集成Facebook時(shí),會(huì)讓填入Facebook Key Hash,雖說(shuō)大公司的文字描述挺專(zhuān)業(yè)的,并且提供了獲取F...
    jimmy_Hu閱讀 5,891評(píng)論 0 2

友情鏈接更多精彩內(nèi)容