Skip to content

Instantly share code, notes, and snippets.

@viviancromwell
Last active June 16, 2017 13:03
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save viviancromwell/ab540606af94b2ff858c to your computer and use it in GitHub Desktop.
Save viviancromwell/ab540606af94b2ff858c to your computer and use it in GitHub Desktop.
Infinite list with RN (OnScroll: How to update the renderModel)
onScroll(e) {
this.updateRenderModel(e.nativeEvent.contentOffset);
}
render() {
var items = this.state.renderModel.map(renderItem => {
const itemStyle = {
position : 'absolute',
height : ITEM_SIZE,
left : 0,
top : renderItem.position,
};
return <View key={renderItem.key} style={itemStyle}><Text style={styles.item}>{renderItem.data}</Text></View>;
});
return (
<View style={styles.container}>
<ScrollView ref="scrollView" style={{flex: 1}} scrollEventThrottle={1} onScroll={this.onScroll.bind(this)}>
<View style={{height: this.state.bodyHeight, width: 480}}>
{items}
</View>
</ScrollView>
</View>
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment