Created
January 27, 2017 00:03
-
-
Save ThrowJojo/40c8dfe17da40db718ee0904030de478 to your computer and use it in GitHub Desktop.
Creating lists with section headers in React Native
This file contains 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
let timestamps = [ | |
{ timestamp: Date.now(), period: Periods.ONE }, | |
{ timestamp: Date.now(), period: Periods.ONE }, | |
{ timestamp: Date.now(), period: Periods.ONE }, | |
{ timestamp: Date.now(), period: Periods.THREE }, | |
{ timestamp: Date.now(), period: Periods.FOUR } | |
]; | |
function createTimestampMap(timestamps) { | |
let categoryMap = {}; | |
Object.keys(Periods).forEach((key) => { | |
let period = Periods[key]; | |
categoryMap[period.label] = []; | |
}); | |
timestamps.forEach((timestamp) => { | |
categoryMap[timestamp.period.label].push(timestamp); | |
}); | |
return categoryMap; | |
} | |
let timestampMap = createTimestampMap(timestamps); | |
let sectionTemplate = new ListView.DataSource({ | |
rowHasChanged: (r1, r2) => r1 !== r2, | |
sectionHeaderHasChanged: (s1, s2) => s1 !== s2 | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment