2017-04-11 29 views
2

我正在使用不同節標題呈現多個部分。我有些麻煩要以我想要的方式顯示它。 我希望將我的標題放置在頂部和底部,作爲網格的部分項目。React native SectionList佈局

This is what I have right now

有了這個代碼:

<SectionList 
     contentContainerStyle={styles.sectionListContainer} 
     renderItem={this.renderItem} 
     keyExtractor={this.getKey} 
     renderSectionHeader={this.renderSectionHeader} 
     shouldItemUpdate={this.shouldItemUpdate} 
     sections={[ 
      { data: mostViewedArray, key: "most_viewed", title: "Most viewed" }, 
      { data: recentlyArray, key: "recently", title: "Recently" } 
     ]} 
     /> 



const styles = StyleSheet.create({ 
    sectionListContainer: { 
    flex: 1, 
    flexDirection: "row", 
    flexWrap: "wrap", 
    justifyContent: "space-between" 
    } 
}); 

所以我希望能夠sectionListContainer的CSS不適用於sectionHeader。但我不確定這是可能的。

如果有人有任何想法,請告訴我!

謝謝!

+1

你可以發佈'renderSectionHeader'的內容嗎?對於標題和項目使用單獨的樣式定義是否存在一些問題(在這裏)(https://facebook.github.io/react-native/docs/sectionlist.html#examples)?從發佈的代碼看來,你並沒有這樣做。 – NiFi

回答

1

爲我們工作的解決方案是強制renderSectionHeader具有整個容器的寬度,從而強制渲染項目到下一行。

如果您更新您的問題以包含renderSectionHeader的內容(正如NiFi所問),我可以提供關於如何更新renderSectionHeader的更詳細的答案。