Skip to content

Instantly share code, notes, and snippets.

@janmonschke
Created February 4, 2016 12:53
Show Gist options
  • Save janmonschke/c9c84b6050683da0c64f to your computer and use it in GitHub Desktop.
Save janmonschke/c9c84b6050683da0c64f to your computer and use it in GitHub Desktop.
ListTest
import React, {
AppRegistry,
Component,
StyleSheet,
Text,
View,
ListView,
RecyclerViewBackedScrollView
} from 'react-native';
const genRandomRow = () => ({ title: Math.random() });
const genRandomSet = () => {
const set = [];
for (var i = 0; i < 30; i++) {
set.push(genRandomRow());
}
return set;
};
var setData = genRandomSet();
class ListTest extends Component {
constructor(props) {
super(props);
this.ds = new ListView.DataSource({rowHasChanged: (r1, r2) => {
console.log('rowHasChanged');
return r1 !== r2;
}});
this.state = {
dataSource: this.ds.cloneWithRows(setData)
}
}
renderRow(data) {
return (
<View style={{height: 80, justifyContent: 'center', alignItems: 'center', borderBottomColor: 'black', borderBottomWidth: 1}}>
<Text>{data.title}</Text>
</View>
);
}
onEndReached = () => {
setData = [...setData, ...genRandomSet()];
this.setState({
dataSource: this.ds.cloneWithRows(setData)
});
console.log('onEndReached');
};
render() {
return (
<ListView
dataSource={this.state.dataSource}
renderRow={this.renderRow}
onEndReached={this.onEndReached}
/>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
welcome: {
fontSize: 20,
textAlign: 'center',
margin: 10,
},
instructions: {
textAlign: 'center',
color: '#333333',
marginBottom: 5,
},
});
AppRegistry.registerComponent('ListTest', () => ListTest);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment