@@ -3,9 +3,9 @@ import XDate from 'xdate';
33import React , { useCallback , useContext , useMemo , useRef , useState } from 'react' ;
44import { FlatList , View , ViewToken } from 'react-native' ;
55
6- import { sameWeek , onSameDateRange } from '../../dateutils' ;
6+ import { sameWeek , onSameDateRange , getWeekDates } from '../../dateutils' ;
77import { toMarkingFormat } from '../../interface' ;
8- import { DateData } from '../../types' ;
8+ import { DateData , MarkedDates } from '../../types' ;
99import styleConstructor from '../style' ;
1010import { CalendarListProps } from '../../calendar-list' ;
1111import WeekDaysNames from '../../commons/WeekDaysNames' ;
@@ -37,6 +37,7 @@ const WeekCalendar = (props: WeekCalendarProps) => {
3737 current,
3838 theme,
3939 testID,
40+ markedDates,
4041 } = props ;
4142 const context = useContext ( CalendarContext ) ;
4243 const { allowShadow = true , ...calendarListProps } = props ;
@@ -92,16 +93,34 @@ const WeekCalendar = (props: WeekCalendarProps) => {
9293 }
9394 } , [ onDayPress ] ) ;
9495
96+ const getCurrentWeekMarkings = useCallback ( ( date : string , markings ?: MarkedDates ) : MarkedDates | undefined => {
97+ if ( ! markings ) {
98+ return ;
99+ }
100+ const dates = getWeekDates ( date , firstDay ) as XDate [ ] | undefined ;
101+ return dates ?. reduce ( ( acc , date ) => {
102+ const dateString = toMarkingFormat ( date ) ;
103+ return {
104+ ...acc ,
105+ ...(
106+ markings [ dateString ] && { [ dateString ] : markings [ dateString ] }
107+ ) ,
108+ } ;
109+ } , { } ) ;
110+ } , [ ] ) ;
111+
95112 const weekStyle = useMemo ( ( ) => {
96113 return [ { width : containerWidth } , propsStyle ] ;
97114 } , [ containerWidth , propsStyle ] ) ;
98115
99116 const renderItem = useCallback ( ( { item} : { item : string } ) => {
100117 const currentContext = sameWeek ( date , item , firstDay ) ? context : undefined ;
118+ const markings = getCurrentWeekMarkings ( item , markedDates ) ;
101119
102120 return (
103121 < Week
104122 { ...others }
123+ markedDates = { markings }
105124 current = { item }
106125 firstDay = { firstDay }
107126 style = { weekStyle }
@@ -111,7 +130,7 @@ const WeekCalendar = (props: WeekCalendarProps) => {
111130 timelineLeftInset = { timelineLeftInset }
112131 />
113132 ) ;
114- } , [ firstDay , _onDayPress , context , date ] ) ;
133+ } , [ firstDay , _onDayPress , context , date , markedDates ] ) ;
115134
116135 const keyExtractor = useCallback ( ( item ) => item , [ ] ) ;
117136
0 commit comments