Last active
January 20, 2016 20:17
-
-
Save janicduplessis/256da082ee010336eaaa to your computer and use it in GitHub Desktop.
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
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