question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

renderSectionHeader docs not very clear

See original GitHub issue

I’m trying to create Instagram photo like sticky headers, but I don’t understand how to structure the data. I’ve seen examples like these:

dataSource : new ListView.DataSource({
            getSectionData          : getSectionData,
            getRowData              : getRowData,
            rowHasChanged           : (row1, row2) => row1 !== row2,
            sectionHeaderHasChanged : (s1, s2) => s1 !== s2
 })

and

dataSource : this.state.dataSource.cloneWithRowsAndSections(dataBlob, sectionIDs, rowIDs)

but I can’t figure out how they work…

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:1
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

8reactions
syousif94commented, Jun 23, 2015

Ok I figured it out.

First I put this in my constructor function:

var getSectionData = (dataBlob, sectionID) => {
      return dataBlob[sectionID];
 }
var getRowData = (dataBlob, sectionID, rowID) => {
      return dataBlob[sectionID + ':' + rowID];
}
this.ds = new ListView.DataSource({
      getSectionData: getSectionData,
      getRowData: getRowData,
      rowHasChanged: (r1, r2) => r1 !== r2,
      sectionHeaderHasChanged: (s1, s2) => s1 !== s2
})  

Then you have to create a dataBlob object, an array of sectionIDs, and an array of rowID arrays with the following formats:

var dataBlob = {
     'sectionID1' : { ...section1 data },
     'sectionID1:rowID1' : { ...row1 data },
     'sectionID1:rowID2' : { ..row2 data },
     'sectionID2' : { ...section2 data },
     'sectionID2:rowID1' : { ...row1 data },
     'sectionID2:rowID2' : { ..row2 data },
     ...
}

var sectionIDs = [ 'sectionID1', 'sectionID2', ... ]

var rowIDs = [ [ 'rowID1', 'rowID2' ], [ 'rowID1', 'rowID2' ], ... ]

Finally, you can create a valid dataSource for your list with:

this.ds.cloneWithRowsAndSections(dataBlob, sectionIDs, rowIDs)

Hope this helps someone else.

1reaction
joshuapintercommented, Jul 25, 2017

@syousif94 Man, now I have to thank you again. I just replaced my convoluted ListView with SectionList and it’s way easier to use. It’s less than half the code required for ListView.

Thanks for the pointer! 🙏

Read more comments on GitHub >

github_iconTop Results From Across the Web

Render 'no content' component when section in SectionList ...
I know for the FlatList component this is possible using the ListEmptyComponent prop, but how does this work for the SectionList component? I ......
Read more >
ListView · React Native
Called when all rows have been rendered and the list has been scrolled to within onEndReachedThreshold of the bottom. The native scroll event...
Read more >
Text - React Native - W3cubDocs
The <Text> element is unique relative to layout: everything inside is no longer using the Flexbox layout but using text layout. This means...
Read more >
SectionList - React Native
SectionList. A performant interface for rendering sectioned lists, supporting the most handy features: Fully cross-platform.
Read more >
Sticky Headers Example - NativeBase
We do not want to display it as a list item. Similarly we implemented renderSectionHeader function, returning section headers, as shown above. Wrapping...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found