最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

javascript - React native SectionList layout - Stack Overflow

matteradmin10PV0评论

I'm using to render multiple sections with a different section header. I'm having some trouble to display it the way I want. I would like to have my header at the top and under it, items of the section as a grid.

This is what I have right now

With this code:

<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"
   }
});

So I'd like to be able to not apply the css of sectionListContainer to sectionHeader. But I'm not sure it is possible.

If anyone has any idea about it, let me know!

Thanks!

I'm using to render multiple sections with a different section header. I'm having some trouble to display it the way I want. I would like to have my header at the top and under it, items of the section as a grid.

This is what I have right now

With this code:

<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"
   }
});

So I'd like to be able to not apply the css of sectionListContainer to sectionHeader. But I'm not sure it is possible.

If anyone has any idea about it, let me know!

Thanks!

Share Improve this question asked Apr 11, 2017 at 16:06 iDamsiDams 1412 silver badges4 bronze badges 1
  • 1 Could you post the contents of renderSectionHeader? Is there some problem with using separate style definitions for the headers and the items as is done here? From the posted code, it appears you are not doing that. – NiFi Commented Apr 11, 2017 at 22:36
Add a ment  | 

1 Answer 1

Reset to default 2

A solution that worked for us, was to force the renderSectionHeader to have the width of the entire container, thereby forcing the render items to the next row.

If you update your question to include the content of renderSectionHeader (as already asked by NiFi), I could provide a more detailed answer on how you would update renderSectionHeader.

Post a comment

comment list (0)

  1. No comments so far