11import React from 'react'
2- import {
2+ import {
33 FlatList ,
44} from 'react-native'
55import FlatListItem from './FlatListItem'
@@ -11,6 +11,10 @@ export default class OptimizedFlatList extends React.PureComponent {
1111 this . state = { }
1212 this . rowRefs = [ ]
1313 this . _onViewableItemsChanged = this . _onViewableItemsChanged . bind ( this )
14+ this . scrollToEnd = this . scrollToEnd . bind ( this )
15+ this . scrollToIndex = this . scrollToIndex . bind ( this )
16+ this . scrollToItem = this . scrollToItem . bind ( this )
17+ this . scrollToOffset = this . scrollToOffset . bind ( this )
1418 }
1519
1620 _addRowRefs ( ref , data ) {
@@ -20,7 +24,7 @@ export default class OptimizedFlatList extends React.PureComponent {
2024 index : data . index ,
2125 }
2226 }
23-
27+
2428 _updateItem ( index , visibility ) {
2529 if ( ! this . rowRefs [ index ] . ref ) {
2630 return false ;
@@ -50,14 +54,49 @@ export default class OptimizedFlatList extends React.PureComponent {
5054 } >
5155 }
5256 ) {
53- info . changed . map ( item =>
57+ info . changed . map ( item =>
5458 this . _updateItem ( item . index , item . isViewable )
5559 )
5660 }
5761
62+ scrollToEnd ( params ?: ?{ animated ?: ?boolean } ) {
63+ if ( this . _listRef ) {
64+ this . _listRef . scrollToEnd ( params ) ;
65+ }
66+ }
67+
68+
69+ scrollToIndex ( params : {
70+ animated ?: ?boolean ,
71+ index : number ,
72+ viewOffset ?: number ,
73+ viewPosition ?: number ,
74+ } ) {
75+ if ( this . _listRef ) {
76+ this . _listRef . scrollToIndex ( params ) ;
77+ }
78+ }
79+
80+ scrollToItem ( params : {
81+ animated ?: ?boolean ,
82+ item : ItemT ,
83+ viewPosition ? : number ,
84+ } ) {
85+ if ( this . _listRef ) {
86+ this . _listRef . scrollToItem ( params ) ;
87+ }
88+ }
89+
90+ scrollToOffset ( params : { animated ?: ?boolean , offset : number } ) {
91+ if ( this . _listRef ) {
92+ this . _listRef . scrollToOffset ( params ) ;
93+ }
94+ }
95+
5896 render ( ) {
5997 return (
6098 < FlatList
99+ ref = { ref => this . _listRef = ref }
61100 { ...this . props }
62101 renderItem = { data => this . _renderItem ( data ) }
63102 onViewableItemsChanged = { this . _onViewableItemsChanged }
0 commit comments