@@ -2,8 +2,8 @@ import get from 'lodash/get';
22import map from 'lodash/map' ;
33import isFunction from 'lodash/isFunction' ;
44import isUndefined from 'lodash/isUndefined' ;
5+ import debounce from 'lodash/debounce' ;
56
6- import PropTypes from 'prop-types' ;
77import XDate from 'xdate' ;
88
99import React , { useCallback , useContext , useEffect , useRef } from 'react' ;
@@ -94,15 +94,15 @@ const AgendaList = (props: AgendaListProps) => {
9494 useEffect ( ( ) => {
9595 if ( date !== _topSection . current ) {
9696 setTimeout ( ( ) => {
97- scrollToSection ( ) ;
97+ scrollToSection ( date ) ;
9898 } , 500 ) ;
9999 }
100100 } , [ ] ) ;
101101
102102 useEffect ( ( ) => {
103103 // NOTE: on first init data should set first section to the current date!!!
104104 if ( updateSource !== UpdateSources . LIST_DRAG && updateSource !== UpdateSources . CALENDAR_INIT ) {
105- scrollToSection ( ) ;
105+ scrollToSection ( date ) ;
106106 }
107107 } , [ date ] ) ;
108108
@@ -158,8 +158,8 @@ const AgendaList = (props: AgendaListProps) => {
158158 return sectionTitle ;
159159 } ;
160160
161- const scrollToSection = ( ) => {
162- const sectionIndex = scrollToNextEvent ? getNextSectionIndex ( date ) : getSectionIndex ( date ) ;
161+ const scrollToSection = useCallback ( debounce ( ( d ) => {
162+ const sectionIndex = scrollToNextEvent ? getNextSectionIndex ( d ) : getSectionIndex ( d ) ;
163163 if ( isUndefined ( sectionIndex ) ) {
164164 return ;
165165 }
@@ -175,7 +175,7 @@ const AgendaList = (props: AgendaListProps) => {
175175 viewOffset : ( constants . isAndroid ? sectionHeight . current : 0 ) + viewOffset
176176 } ) ;
177177 }
178- } ;
178+ } , 1000 , { leading : false , trailing : true } ) , [ ] ) ;
179179
180180 const _onViewableItemsChanged = useCallback ( ( info : { viewableItems : Array < ViewToken > ; changed : Array < ViewToken > } ) => {
181181 if ( info ?. viewableItems && ! sectionScroll . current ) {
@@ -265,15 +265,6 @@ const AgendaList = (props: AgendaListProps) => {
265265export default AgendaList ;
266266
267267AgendaList . displayName = 'AgendaList' ;
268- AgendaList . propTypes = {
269- // ...SectionList.propTypes,
270- dayFormat : PropTypes . string ,
271- dayFormatter : PropTypes . func ,
272- useMoment : PropTypes . bool ,
273- markToday : PropTypes . bool ,
274- sectionStyle : PropTypes . oneOfType ( [ PropTypes . object , PropTypes . number , PropTypes . array ] ) ,
275- avoidDateUpdates : PropTypes . bool
276- } ;
277268AgendaList . defaultProps = {
278269 dayFormat : 'dddd, MMM d' ,
279270 stickySectionHeadersEnabled : true ,
0 commit comments