@@ -8,7 +8,7 @@ import debounce from 'lodash/debounce';
88
99import XDate from 'xdate' ;
1010
11- import React , { useCallback , useContext , useEffect , useMemo , useRef } from 'react' ;
11+ import React , { forwardRef , useCallback , useContext , useEffect , useMemo , useRef } from 'react' ;
1212import {
1313 SectionList ,
1414 DefaultSectionT ,
@@ -19,7 +19,7 @@ import {
1919 ViewToken ,
2020} from 'react-native' ;
2121
22- import { useDidUpdate } from '../hooks' ;
22+ import { useDidUpdate , useCombinedRefs } from '../hooks' ;
2323import { getMoment } from '../momentResolver' ;
2424import { isToday , isGTE , sameDate } from '../dateutils' ;
2525import { parseDate } from '../interface' ;
@@ -41,7 +41,7 @@ const viewabilityConfig = {
4141 * @extends : SectionList
4242 * @example : https://github.com/wix/react-native-calendars/blob/master/example/src/screens/expandableCalendar.js
4343 */
44- const AgendaList = ( props : AgendaListProps ) => {
44+ const AgendaList = forwardRef ( ( props : AgendaListProps , ref : any ) => {
4545 if ( props . infiniteListProps ) {
4646 return < InfiniteAgendaList { ...props } /> ;
4747 }
@@ -69,7 +69,7 @@ const AgendaList = (props: AgendaListProps) => {
6969 const { date, updateSource, setDate, setDisabled} = useContext ( Context ) ;
7070
7171 const style = useRef ( styleConstructor ( theme ) ) ;
72- const list = useRef < any > ( ) ;
72+ const list = useCombinedRefs ( ref ) ;
7373 const _topSection = useRef ( sections [ 0 ] ?. title ) ;
7474 const didScroll = useRef ( false ) ;
7575 const sectionScroll = useRef ( false ) ;
@@ -151,6 +151,7 @@ const AgendaList = (props: AgendaListProps) => {
151151 sectionScroll . current = true ; // to avoid setDate() in onViewableItemsChanged
152152 _topSection . current = sections [ sectionIndex ] ?. title ;
153153
154+ // @ts -expect-error should be fixed when we fix the typings of the ref.
154155 list ?. current . scrollToLocation ( {
155156 animated : true ,
156157 sectionIndex : sectionIndex ,
@@ -228,6 +229,7 @@ const AgendaList = (props: AgendaListProps) => {
228229 < SectionList
229230 stickySectionHeadersEnabled
230231 { ...props }
232+ // @ts -expect-error
231233 ref = { list }
232234 keyExtractor = { _keyExtractor }
233235 showsVerticalScrollIndicator = { false }
@@ -245,7 +247,7 @@ const AgendaList = (props: AgendaListProps) => {
245247 // _getItemLayout = (data, index) => {
246248 // return {length: constants.screenWidth, offset: constants.screenWidth * index, index};
247249 // }
248- } ;
250+ } ) ;
249251
250252export default AgendaList ;
251253
@@ -255,6 +257,7 @@ AgendaList.propTypes = {
255257 dayFormatter : PropTypes . func ,
256258 useMoment : PropTypes . bool ,
257259 markToday : PropTypes . bool ,
260+ // @ts -expect-error TODO Figure out why forwardRef causes error about the number type
258261 sectionStyle : PropTypes . oneOfType ( [ PropTypes . object , PropTypes . number , PropTypes . array ] ) ,
259262 avoidDateUpdates : PropTypes . bool
260263} ;
0 commit comments