Last active
August 29, 2015 14:21
-
-
Save lhahne/8d0d038a7d3fd65fcde4 to your computer and use it in GitHub Desktop.
react native view
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
var React = require('react-native') | |
var {Text, ListView, AppRegistry} = React | |
var StationMetadataStore = require('./StationMetadataStore') | |
var StationList = React.createClass({ | |
getInitialState() { | |
var ds = new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2}) | |
return {stations: ds.cloneWithRows([])} | |
}, | |
componentDidMount() { | |
this.unsubscribe = | |
StationMetadataStore.stationsByCode.onValue(stationCodes => { | |
this.setState({ | |
stations: this.state.stations.cloneWithRows(stationCodes) | |
}) | |
}) | |
}, | |
componentWillUnmount() { | |
this.unsubscribe() | |
}, | |
render() { | |
return <ListView | |
dataSource={this.state.stations} | |
renderRow={(rowData) => <Text>{rowData.stationShortCode}: {rowData.stationName}</Text>} | |
pageSize="20" /> | |
} | |
}) | |
AppRegistry.registerComponent('StationList', () => StationList) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment