@@ -592,22 +592,6 @@ class VirtualizedList extends React.PureComponent<Props, State> {
592592 this . state = initialState ;
593593 }
594594
595- componentDidMount ( ) {
596- if ( this . props . initialScrollIndex ) {
597- this . _initialScrollIndexTimeout = setTimeout (
598- ( ) =>
599- /* $FlowFixMe(>=0.63.0 site=react_native_fb) This comment suppresses
600- * an error found when Flow v0.63 was deployed. To see the error
601- * delete this comment and run Flow. */
602- this . scrollToIndex ( {
603- animated : false ,
604- index : this . props . initialScrollIndex ,
605- } ) ,
606- 0 ,
607- ) ;
608- }
609- }
610-
611595 componentWillUnmount ( ) {
612596 if ( this . _isNestedWithSameOrientation ( ) ) {
613597 this . context . virtualizedList . unregisterAsNestedChild ( {
@@ -625,10 +609,6 @@ class VirtualizedList extends React.PureComponent<Props, State> {
625609 tuple . viewabilityHelper . dispose ( ) ;
626610 } ) ;
627611 this . _fillRateHelper . deactivateAndFlush ( ) ;
628- /* $FlowFixMe(>=0.63.0 site=react_native_fb) This comment suppresses an
629- * error found when Flow v0.63 was deployed. To see the error delete this
630- * comment and run Flow. */
631- clearTimeout ( this . _initialScrollIndexTimeout ) ;
632612 }
633613
634614 componentWillReceiveProps ( newProps : Props ) {
@@ -954,7 +934,7 @@ class VirtualizedList extends React.PureComponent<Props, State> {
954934 _highestMeasuredFrameIndex = 0 ;
955935 _headerLength = 0 ;
956936 _indicesToKeys: Map < number , string > = new Map ( ) ;
957- _initialScrollIndexTimeout = 0 ;
937+ _hasDoneInitialScroll = false ;
958938 _nestedChildLists: Map <
959939 string ,
960940 { ref : ?VirtualizedList , state : ?ChildListState } ,
@@ -1206,6 +1186,19 @@ class VirtualizedList extends React.PureComponent<Props, State> {
12061186 }
12071187
12081188 _onContentSizeChange = ( width : number , height : number ) => {
1189+ if (
1190+ width > 0 &&
1191+ height > 0 &&
1192+ this . props . initialScrollIndex != null &&
1193+ this . props . initialScrollIndex > 0 &&
1194+ ! this . _hasDoneInitialScroll
1195+ ) {
1196+ this . scrollToIndex ( {
1197+ animated : false ,
1198+ index : this . props . initialScrollIndex ,
1199+ } ) ;
1200+ this . _hasDoneInitialScroll = true ;
1201+ }
12091202 if ( this . props . onContentSizeChange ) {
12101203 this . props . onContentSizeChange ( width , height ) ;
12111204 }
0 commit comments