11import PropTypes from 'prop-types' ;
22import XDate from 'xdate' ;
3-
3+ import isEmpty from 'lodash/isEmpty' ;
44import React , { useRef , useState , useEffect , useCallback , useMemo } from 'react' ;
55import { View , ViewStyle , StyleProp } from 'react-native' ;
66// @ts -expect-error
@@ -11,7 +11,7 @@ import {page, isGTE, isLTE, sameMonth} from '../dateutils';
1111import { xdateToData , parseDate , toMarkingFormat } from '../interface' ;
1212import { getState } from '../day-state-manager' ;
1313import { extractHeaderProps , extractDayProps } from '../componentUpdater' ;
14- import { DateData , Theme , MarkedDates } from '../types' ;
14+ import { DateData , Theme , MarkedDates , ContextProp } from '../types' ;
1515import { useDidUpdate } from '../hooks' ;
1616import styleConstructor from './style' ;
1717import CalendarHeader , { CalendarHeaderProps } from './header' ;
@@ -70,7 +70,7 @@ export interface CalendarProps extends CalendarHeaderProps, DayProps {
7070 * @example : https://github.com/wix/react-native-calendars/blob/master/example/src/screens/calendars.js
7171 * @gif : https://github.com/wix/react-native-calendars/blob/master/demo/assets/calendar.gif
7272 */
73- const Calendar = ( props : CalendarProps ) => {
73+ const Calendar = ( props : CalendarProps & ContextProp ) => {
7474 const {
7575 initialDate,
7676 current,
@@ -198,14 +198,15 @@ const Calendar = (props: CalendarProps) => {
198198 }
199199
200200 const dateString = toMarkingFormat ( day ) ;
201+ const isControlled = isEmpty ( props . context ) ;
201202
202203 return (
203204 < View style = { style . current . dayContainer } key = { id } >
204205 < Day
205206 { ...dayProps }
206207 testID = { `${ testID } .day_${ dateString } ` }
207208 date = { dateString }
208- state = { getState ( day , currentMonth , props ) }
209+ state = { getState ( day , currentMonth , props , isControlled ) }
209210 marking = { markedDates ?. [ dateString ] }
210211 onPress = { _onDayPress }
211212 onLongPress = { onLongPressDay }
0 commit comments