Skip to content

Instantly share code, notes, and snippets.

@janicduplessis
Last active January 20, 2016 20:17
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 janicduplessis/256da082ee010336eaaa to your computer and use it in GitHub Desktop.
Save janicduplessis/256da082ee010336eaaa to your computer and use it in GitHub Desktop.
const React = require('react');
const {
ListView,
RefreshControl,
} = React;
React.createClass({
getInitialState() {
const ds = new ListView.DataSource({
rowHasChanged: (r1, r2) => r1 !== r2,
sectionHeaderHasChanged: (r1, r2) => r1 !== r2,
});
return {
dataSource: ds.cloneWithRowsAndSections(this._genRows([])),
refreshing: false,
};
},
render() {
return (
<ListView
dataSource={this.state.dataSource
renderRow={this._renderRow}
renderSection={this._renderSection}
refreshControl={
<RefreshControl
refreshing={this.state.refreshing}
onRefresh={this._onRefresh}
/>
}>
/>
);
},
_onRefresh() {
this.setState({refreshing: true});
fetchData().then((newData) => {
this.setState({
refreshing: false
dataSource: this.state.dataSource.cloneWithRowsAndSections(this._genRows(newData))
});
});
},
_genRows(data) {
// Return an object like
// {
// 'section1': ['row1', 'row2', 'row3'],
// 'section2': ['row1', 'row2', 'row3'],
// }
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment