Skip to content

Instantly share code, notes, and snippets.

@desmond-dsouza
Last active January 22, 2018 08:46
Show Gist options
  • Save desmond-dsouza/c4cc3ba46e1c65ac659675a0d01ade7d to your computer and use it in GitHub Desktop.
Save desmond-dsouza/c4cc3ba46e1c65ac659675a0d01ade7d to your computer and use it in GitHub Desktop.
bs-react-native + SectionList - How to store / retrieve section header info like in this Js?
import React from 'react';
import {Alert, SectionList, View, ScrollView, Text, StyleSheet} from 'react-native';
const data = [
{key: 'Devin'},
{key: 'Jackson'},
{key: 'James'},
{key: 'Joel'},
{key: 'John'},
{key: 'Jillian'},
{key: 'Jimmy'},
{key: 'Julie'},
{key: 'Amy'},
{key: 'Andrew'},
];
sections = [
{title: 'A', data: data.slice(0,4)},
{title: 'B', data: data.slice(5,9)},
{title: 'C', data: data.slice(4,7)},
];
export default class Lists extends React.Component {
render () {
return (
<ScrollView style={styles.container}>
<SectionList
sections={sections}
renderItem={({item}) => <Text style={styles.item}>{"Item: " + item.key}</Text>}
renderSectionHeader={({section}) => <Text style={styles.sectionHeader}>{section.title}</Text>}
keyExtractor={(item, index) => index}
/>
</ScrollView>
)
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
paddingTop: 22
},
item: {
padding: 10,
fontSize: 18,
height: 44,
},
sectionHeader: {
paddingTop: 2,
paddingLeft: 10,
paddingRight: 10,
paddingBottom: 2,
fontSize: 14,
fontWeight: 'bold',
backgroundColor: 'rgba(200,200,200,1.0)',
},
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment