Created
January 23, 2017 15:20
-
-
Save MarkMurphy/310e7801b497381854b6ea713eb4e42f to your computer and use it in GitHub Desktop.
React Native Web - ListViewDemo
This file contains hidden or 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
import React, { Component } from 'react'; | |
import { ListView, StyleSheet } from 'react-native'; | |
const styles = StyleSheet.create({ | |
container: { | |
flex: 1, | |
marginTop: 20, | |
}, | |
row: { | |
padding: '10px' | |
} | |
}); | |
class Row extends Component { | |
render() { | |
return <div style={{padding: '10px'}}>{this.props.children}</div> | |
} | |
} | |
class ListViewDemo extends Component { | |
constructor(props) { | |
super(props); | |
const ds = new ListView.DataSource({ | |
rowHasChanged: (r1, r2) => (r1 !== r2), | |
}); | |
const data = this._genRows() | |
this.state = { | |
dataSource: ds.cloneWithRows(data), | |
}; | |
} | |
_genRows() { | |
let dataBlob = []; | |
for (let i = 0; i < 500; i++) { | |
dataBlob.push('Row ' + i); | |
} | |
return dataBlob; | |
} | |
_renderRow(rowData) { | |
return ( | |
<Row style={styles.row}>{rowData}</Row> | |
); | |
} | |
render() { | |
return ( | |
<div style={{height: '500px', positiion: 'relative', overflow: 'hidden'}}> | |
<ListView | |
style={styles.container} | |
dataSource={this.state.dataSource} | |
renderRow={this._renderRow} | |
initialListSize={10} | |
scrollRenderAheadDistance={1} | |
pageSize={1} | |
/> | |
</div> | |
); | |
} | |
} | |
export default ListViewDemo; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment