javascript - react native SectionList 布局

标签 javascript css react-native react-native-flatlist

我正在使用不同的节标题来呈现多个节。我在按我想要的方式显示它时遇到了一些麻烦。 我希望我的标题位于顶部和下方,该部分的元素作为网格。

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。但我不确定这是否可能。

如果有人对此有任何想法,请告诉我!

谢谢!

最佳答案

一个对我们有用的解决方案是强制 renderSectionHeader 具有整个容器的宽度,从而强制渲染元素到下一行。

如果您更新您的问题以包含 renderSectionHeader 的内容(正如 NiFi 已经提出的那样),我可以就您将如何更新 renderSectionHeader 提供更详细的答案。

关于javascript - react native SectionList 布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43351080/

相关文章:

javascript - (#200) 用户未授权应用程序执行此操作

css - 像背景大小 : cover 一样缩放和重新定位 iframe

php - 在 Wordpress 中使用 PHP 和 CSS 编辑帖子页面?

reactjs - 获取 FlatList 中所选项目的值。 -- react native

javascript - 如何在 const 方法中返回

ASP.NET GridView : How can we find which column was selected in gridview

javascript - 使用 javascript 动态聚焦于某个元素

html - Bootstrap Carousel 自动滚动和 'Next' 和 'Prev' 不工作

react-native - 如何在我的 react-native 应用程序中使用 fontawesome 灯图标?

javascript - stopPropagation 与 stopImmediatePropagation