@@ -6,12 +6,10 @@ import React, {forwardRef, useImperativeHandle, useRef, useEffect, useState, use
66import { FlatList , View , ViewStyle , FlatListProps } from 'react-native' ;
77
88import { extractHeaderProps , extractCalendarProps } from '../componentUpdater' ;
9- import { xdateToData , parseDate } from '../interface' ;
9+ import { xdateToData , parseDate , toMarkingFormat } from '../interface' ;
1010import { page , sameDate , sameMonth } from '../dateutils' ;
1111import constants from '../commons/constants' ;
1212import { useDidUpdate } from '../hooks' ;
13- // @ts -expect-error
14- import { STATIC_HEADER } from '../testIDs' ;
1513import styleConstructor from './style' ;
1614import Calendar , { CalendarProps } from '../calendar' ;
1715import CalendarListItem from './item' ;
@@ -102,7 +100,7 @@ const CalendarList = (props: CalendarListProps, ref: any) => {
102100 onEndReachedThreshold,
103101 onEndReached
104102 } = props ;
105-
103+
106104 const calendarProps = extractCalendarProps ( props ) ;
107105 const headerProps = extractHeaderProps ( props ) ;
108106 const calendarSize = horizontal ? calendarWidth : calendarHeight ;
@@ -133,8 +131,8 @@ const CalendarList = (props: CalendarListProps, ref: any) => {
133131 } , [ propsStyle ] ) ;
134132
135133 const initialDateIndex = useMemo ( ( ) => {
136- return findIndex ( items , function ( item ) {
137- return item . toString ( ) === initialDate . current ?. toString ( ) ;
134+ return findIndex ( items , function ( item ) {
135+ return item . toString ( ) === initialDate . current ?. toString ( ) ;
138136 } ) ;
139137 } , [ items ] ) ;
140138
@@ -180,7 +178,7 @@ const CalendarList = (props: CalendarListProps, ref: any) => {
180178 const scrollTo = parseDate ( date ) ;
181179 const diffMonths = Math . round ( initialDate ?. current ?. clone ( ) . setDate ( 1 ) . diffMonths ( scrollTo ?. clone ( ) . setDate ( 1 ) ) ) ;
182180 const scrollAmount = calendarSize * pastScrollRange + diffMonths * calendarSize ;
183-
181+
184182 if ( scrollAmount !== 0 ) {
185183 // @ts -expect-error
186184 list ?. current ?. scrollToOffset ( { offset : scrollAmount , animated : animateScroll } ) ;
@@ -196,8 +194,8 @@ const CalendarList = (props: CalendarListProps, ref: any) => {
196194 setCurrentMonth ( day ) ;
197195 } , [ currentMonth , scrollToMonth ] ) ;
198196
199- const getMarkedDatesForItem = useCallback ( ( item ?: XDate ) => {
200- if ( markedDates && item ) {
197+ const getMarkedDatesForItem = useCallback ( ( item ?: XDate ) => {
198+ if ( markedDates && item ) {
201199 for ( const [ key , _ ] of Object . entries ( markedDates ) ) {
202200 if ( sameMonth ( new XDate ( key ) , new XDate ( item ) ) ) {
203201 return markedDates ;
@@ -224,13 +222,16 @@ const CalendarList = (props: CalendarListProps, ref: any) => {
224222 return false ;
225223 } , [ currentMonth ] ) ;
226224
227- const renderItem = useCallback ( ( { item} : any ) => {
225+ const renderItem = useCallback ( ( { item} : { item : XDate } ) => {
226+ const dateString = toMarkingFormat ( item ) ;
227+ const [ year , month ] = dateString . split ( '-' ) ;
228+ const testId = `${ testID } .item_${ year } -${ month } ` ;
228229 return (
229230 < CalendarListItem
230231 { ...calendarProps }
232+ testID = { testId }
231233 markedDates = { getMarkedDatesForItem ( item ) }
232234 item = { item }
233- testID = { `${ testID } _${ item } ` }
234235 style = { calendarStyle }
235236 // @ts -expect-error - type mismatch - ScrollView's 'horizontal' is nullable
236237 horizontal = { horizontal }
@@ -247,7 +248,7 @@ const CalendarList = (props: CalendarListProps, ref: any) => {
247248 return (
248249 < CalendarHeader
249250 { ...headerProps }
250- testID = { STATIC_HEADER }
251+ testID = { ` ${ testID } .staticHeader` }
251252 style = { staticHeaderStyle }
252253 month = { currentMonth }
253254 addMonth = { addMonth }
@@ -273,7 +274,7 @@ const CalendarList = (props: CalendarListProps, ref: any) => {
273274 } , [ ] ) ;
274275
275276 const viewabilityConfigCallbackPairs = useRef ( [
276- {
277+ {
277278 viewabilityConfig : viewabilityConfig . current ,
278279 onViewableItemsChanged
279280 } ,
@@ -291,7 +292,7 @@ const CalendarList = (props: CalendarListProps, ref: any) => {
291292 renderItem = { renderItem }
292293 getItemLayout = { getItemLayout }
293294 initialNumToRender = { range . current }
294- initialScrollIndex = { initialDateIndex }
295+ initialScrollIndex = { initialDateIndex }
295296 viewabilityConfigCallbackPairs = { viewabilityConfigCallbackPairs . current }
296297 testID = { testID }
297298 onLayout = { onLayout }
0 commit comments