Call scrollToIndex only if flatListRef.current is not null (#3022)

This commit is contained in:
Miguel Alatzar 2019-07-23 11:21:38 -07:00 committed by Elias Nahum
parent 995704df00
commit f117281bec
No known key found for this signature in database
GPG key ID: E038DB71E0B61702

View file

@ -292,16 +292,17 @@ export default class PostList extends PureComponent {
width > 0 &&
height > 0 &&
this.props.initialIndex > 0 &&
!this.hasDoneInitialScroll &&
this.flatListRef?.current
!this.hasDoneInitialScroll
) {
requestAnimationFrame(() => {
this.flatListRef.current.scrollToIndex({
animated: false,
index: this.props.initialIndex,
viewOffset: 0,
viewPosition: 1, // 0 is at bottom
});
if (this.flatListRef?.current) {
this.flatListRef.current.scrollToIndex({
animated: false,
index: this.props.initialIndex,
viewOffset: 0,
viewPosition: 1, // 0 is at bottom
});
}
});
this.hasDoneInitialScroll = true;
}