2017-04-11 26 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的更详细的答案。