-
Notifications
You must be signed in to change notification settings - Fork 24.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
renderSectionHeader docs not very clear #1706
Comments
@syousif94 Here is a nice blog post I found earlier today actually about using section headers: http://moduscreate.com/react-native-listview-with-section-headers/ |
@dhrrgn that's where I got those code snippets from. I have trouble following the manipulation of their data. |
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. |
Nice, thanks for the follow up @syousif94! |
@syousif94 you're a star, thanks! |
Thank you @syousif94! 👍 Felt like I was missing something. This should be included in the main docs somewhere. Still seems overly complicated for just a ListView with sections but at least we know to do it now. :) |
@nazywamsiepawel @joshuapinter y'all should switch to SectionList if the version of RN you're using supports it. Way easier to use. |
@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! 🙏 |
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:
and
but I can't figure out how they work...
The text was updated successfully, but these errors were encountered: