Skip to content

Instantly share code, notes, and snippets.

@jamesreggio
Created July 28, 2017 13:28
Show Gist options
  • Save jamesreggio/47904fb20b3a142172ef701113abbc4e to your computer and use it in GitHub Desktop.
Save jamesreggio/47904fb20b3a142172ef701113abbc4e to your computer and use it in GitHub Desktop.
Repro for an issue with frame calculations in VirtualizedList in React Native 0.46.4
import React, { Component } from 'react';
import {
AppRegistry,
StyleSheet,
FlatList,
Text,
View
} from 'react-native';
const ITEMS = 100;
const ITEM_HEIGHT = 200;
const PADDING_TOP = 150;
const PADDING_BOTTOM = 150;
export default class reproVirtualizedList extends Component {
componentDidMount() {
setTimeout(() => {
this.list.scrollToEnd();
}, 2000);
setTimeout(() => {
this.list.scrollToIndex({
index: 50,
viewPosition: 0,
});
}, 3000);
}
render() {
const ref = (ref) => this.list = ref;
const data = Array.from({length: ITEMS}).map((_, key) => ({key}));
return (
<FlatList
ref={ref}
data={data}
renderItem={this.renderItem}
style={styles.container}
contentContainerStyle={styles.content}
/>
);
}
renderItem({index}) {
return (
<View style={styles.item}>
<Text>{index}</Text>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
},
content: {
paddingTop: PADDING_TOP,
paddingBottom: PADDING_BOTTOM,
backgroundColor: '#cccccc',
},
item: {
height: ITEM_HEIGHT,
backgroundColor: '#ffffff',
borderTopWidth: 1,
borderTopColor: '#666666',
borderBottomWidth: 1,
borderBottomColor: '#666666',
justifyContent: 'center',
alignItems: 'center',
},
});
AppRegistry.registerComponent('reproVirtualizedList', () => reproVirtualizedList);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment