@@ -2,7 +2,7 @@ import PropTypes from 'prop-types';
22
33import isUndefined from 'lodash/isUndefined' ;
44import debounce from 'lodash/debounce' ;
5- import InfiniteList , { InfiniteListProps } from '../infinite-list' ;
5+ import InfiniteList from '../infinite-list' ;
66
77import XDate from 'xdate' ;
88
@@ -58,12 +58,14 @@ const InfiniteAgendaList = (props: AgendaListProps) => {
5858 const didScroll = useRef ( false ) ;
5959 const sectionScroll = useRef ( false ) ;
6060 const [ data , setData ] = useState ( [ ] as any [ ] ) ;
61+ const dataRef = useRef ( data ) ;
6162
6263 useEffect ( ( ) => {
6364 const items = sections . reduce ( ( acc : any , cur : any ) => {
6465 return [ ...acc , { title : cur . title , isTitle : true } , ...cur . data ] ;
6566 } , [ ] ) ;
6667 setData ( items ) ;
68+ dataRef . current = items ;
6769
6870 if ( date !== _topSection . current ) {
6971 setTimeout ( ( ) => {
@@ -128,29 +130,34 @@ const InfiniteAgendaList = (props: AgendaListProps) => {
128130 return sectionTitle ;
129131 } , [ ] ) ;
130132
131- const scrollToSection = useCallback ( debounce ( ( d ) => {
132- const sectionIndex = scrollToNextEvent ? getNextSectionIndex ( d ) : getSectionIndex ( d ) ;
133+ const scrollToSection = useCallback ( debounce ( ( requestedDate ) => {
134+ const sectionIndex = scrollToNextEvent ? getNextSectionIndex ( requestedDate ) : getSectionIndex ( requestedDate ) ;
133135 if ( isUndefined ( sectionIndex ) ) {
134136 return ;
135137 }
136138
137139 if ( list ?. current && sectionIndex !== undefined ) {
138140 sectionScroll . current = true ; // to avoid setDate() in _onVisibleIndicesChanged
139- _topSection . current = sections [ findItemTitleIndex ( sectionIndex ) ] ?. title ;
141+ if ( requestedDate !== _topSection . current ) {
142+ _topSection . current = sections [ findItemTitleIndex ( sectionIndex ) ] ?. title ;
143+ list . current ?. scrollToIndex ( sectionIndex , true ) ;
144+ }
140145
141- list . current ?. scrollToIndex ( sectionIndex , true ) ;
146+ setTimeout ( ( ) => {
147+ _onMomentumScrollEnd ( ) ; // the RecyclerListView doesn't trigger onMomentumScrollEnd when calling scrollToSection
148+ } , 500 ) ;
142149 }
143- } , 1000 , { leading : false , trailing : true } ) , [ sections ] ) ;
150+ } , 1000 , { leading : false , trailing : true } ) , [ sections ] ) ;
144151
145152 const layoutProvider = useMemo (
146153 ( ) => new LayoutProvider (
147- ( index ) => data [ index ] ?. isTitle ? 'title' : 'page' ,
154+ ( index ) => dataRef . current [ index ] ?. isTitle ? 'title' : 'page' ,
148155 ( type , dim ) => {
149156 dim . width = constants . screenWidth ;
150157 dim . height = type === 'title' ? infiniteListProps ?. titleHeight ?? 60 : infiniteListProps ?. itemHeight ?? 80 ;
151158 }
152159 ) ,
153- [ data ]
160+ [ ]
154161 ) ;
155162
156163 const _onScroll = useCallback ( ( rawEvent : any ) => {
@@ -233,7 +240,7 @@ const InfiniteAgendaList = (props: AgendaListProps) => {
233240 ref = { list }
234241 renderItem = { _renderItem }
235242 data = { data }
236- style = { infiniteListProps ?. style as InfiniteListProps [ 'style' ] }
243+ style = { style . current . container }
237244 layoutProvider = { layoutProvider }
238245 onScroll = { _onScroll }
239246 onVisibleIndicesChanged = { _onVisibleIndicesChanged }
0 commit comments