import * as React from 'react' ; import { FlatList , NativeSyntheticEvent , NativeScrollEvent , ListRenderItemInfo } from 'react-native' ; import { noop } from '../../utils' ; import { VirtualListProps } from './PropsType' ; import { ScrollViewProps } from '../ScrollView/PropsType' ; class _VirtualList extends React . Component < VirtualListProps < any > & ScrollViewProps < any > , any > { static defaultProps = { upperThreshold : 50 , lowerThreshold : 50 , enableBackToTop : false , layout : 'vertical' , overscanCount : 1 } ; scrollViewStartOffsetY = 0 ; scrollUpdateWasRequested = false ; state = { } ; $ref = React . createRef < any > ( ) ; param event private _onScrollBeginDrag = ( e ) : void => { const { layout } = this . props ; const offsetY = e . nativeEvent . contentOffset [ layout === 'vertical' ? 'y' : 'x' ] ; this . scrollViewStartOffsetY = offsetY ; } ; _onScroll = ( e ) : void => { const { onScroll = noop , layout , onScrollNative = noop } = this . props ; onScrollNative ( e ) ; const offsetY = e . nativeEvent . contentOffset [ layout === 'vertical' ? 'y' : 'x' ] ; onScroll ( { onScroll : this . scrollViewStartOffsetY < offsetY ? 'forward' : 'backward' , scrollOffset : Math . abs ( this . scrollViewStartOffsetY - offsetY ) , scrollUpdateWasRequested : this . scrollUpdateWasRequested } ) ; } ; scrollTo = ( { offset } ) : void => { const node = this . $ref . current ; if ( node ) { ( node as FlatList < any > ) . scrollToOffset ( { offset , animated : ! ! this . props . scrollWithAnimation } ) ; } } ; scrollToItem = ( { offset } ) : void => { const node = this . $ref . current ; if ( node ) { ( node as FlatList < any > ) . scrollToOffset ( { offset , animated : ! ! this . props . scrollWithAnimation } ) ; } } ; render ( ) { const { itemData , itemSize , layout , overscanCount , children , ... restProps } = this . props ; const itemStyle = layout === 'vertical' ? { height : itemSize } : { width : itemSize } ; const itemRow = ( { item , index , separators } ) => React . createElement ( children , { data : itemData , key : index , index , item , separators , style : { ... itemStyle } } ) ; return ( < FlatList { ... restProps } data = { itemData } windowSize = { overscanCount } horizontal = { layout === 'horizontal' } ref = { this . $ref } onScroll = { this . _onScroll } onScrollBeginDrag = { this . _onScrollBeginDrag } renderItem = { itemRow } keyExtractor = { ( _item , index ) => index + '' } />); } } export default _VirtualList ;