Created
May 20, 2016 20:10
-
-
Save tomprogers/cca2e0001a6339eef7e1379fc8eef481 to your computer and use it in GitHub Desktop.
An explanation of the structures and interpretations of the arguments to cloneWithRowsAndSections
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// somewhere, you had to set this up | |
const LVDS = new ListView.DataSource({ | |
getSectionHeaderData: (blob, sectionId) => blob.sectionData[sectionId], | |
getRowData: (blob, sectionId, rowId) => blob.rowData[rowId] | |
}); | |
// ... and then you had to feed data into it with this: | |
let newListData = LVDS.cloneWithRowsAndSections(blob, sectionIds, rowIdsBySection) | |
// but what do blob, sectionIds, and rowIdsBySection look like, and how are they used internally by ListView? | |
// | |
// Imagine that we've got a list of the digits 1-6 and want to present them in two sections: 'Odds' and 'Evens' | |
// this is what the data would look like that must be fed into cloneWithRowsAndSections | |
blob = { | |
sectionData: { | |
// one of these objects for each section; 'evens' and 'odds' are sectionIds | |
'evens': { text: '-- The Even Numbers --' }, | |
'odds': { text: '-- The Odd Numbers --' } | |
}, | |
rowData: { | |
// one of these objects for each row, 'one' & 'two' are rowIds, etc. | |
'one': { digit: 1, wordLength: 3, name: 'One' }, | |
'two': { digit: 2, wordLength: 3, name: 'Two' }, | |
'three': { digit: 3, wordLength: 5, name: 'Three' }, | |
'four': { digit: 4, wordLength: 4, name: 'Four' }, | |
'five': { digit: 5, wordLength: 4, name: 'Five' }, | |
'six': { digit: 6, wordLength: 3, name: 'Six' } | |
} | |
}; | |
// must be fed into cloneWithRowsAndSections | |
// must contain every sectionId that you wish to display, in display order | |
sectionIds = [ | |
'odds', | |
'evens' | |
]; | |
// must be fed into cloneWithRowsAndSections | |
// each array is a single section's table-of-contents, and lists the rowIds that belong in that section | |
// this list is cross-referenced with sectionIds (above) by array index, e.g.: when rendering | |
// the 'evens' section (which has arrayIndex===1), ListView will include the rows named in rowIdsBySection[ 1 ] | |
rowIdsBySection = [ | |
[ 'one', 'three', 'five' ], | |
[ 'two', 'four', 'six' ] | |
]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment