Skip to content

Instantly share code, notes, and snippets.

@ThrowJojo
Created January 27, 2017 00:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ThrowJojo/40c8dfe17da40db718ee0904030de478 to your computer and use it in GitHub Desktop.
Save ThrowJojo/40c8dfe17da40db718ee0904030de478 to your computer and use it in GitHub Desktop.
Creating lists with section headers in React Native
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