diff --git a/src/calendar/index.tsx b/src/calendar/index.tsx index c2a0b3ac3..b24d86936 100644 --- a/src/calendar/index.tsx +++ b/src/calendar/index.tsx @@ -1,21 +1,24 @@ +import isEmpty from 'lodash/isEmpty'; import PropTypes from 'prop-types'; +import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react'; +import { StyleProp, View, ViewStyle } from 'react-native'; import XDate from 'xdate'; import isEmpty from 'lodash/isEmpty'; import React, {useRef, useState, useEffect, useCallback, useMemo} from 'react'; import {AccessibilityInfo, View, ViewStyle, StyleProp} from 'react-native'; // @ts-expect-error -import GestureRecognizer, {swipeDirections} from 'react-native-swipe-gestures'; +import GestureRecognizer, { swipeDirections } from 'react-native-swipe-gestures'; import constants from '../commons/constants'; -import {page, isGTE, isLTE, sameMonth} from '../dateutils'; -import {xdateToData, parseDate, toMarkingFormat} from '../interface'; -import {getState} from '../day-state-manager'; -import {extractHeaderProps, extractDayProps} from '../componentUpdater'; -import {DateData, Theme, MarkedDates, ContextProp} from '../types'; -import {useDidUpdate} from '../hooks'; -import styleConstructor from './style'; -import CalendarHeader, {CalendarHeaderProps} from './header'; -import Day, {DayProps} from './day/index'; +import { extractDayProps, extractHeaderProps } from '../componentUpdater'; +import { isGTE, isLTE, page, sameMonth } from '../dateutils'; +import { getState } from '../day-state-manager'; +import { useDidUpdate } from '../hooks'; +import { parseDate, toMarkingFormat, xdateToData } from '../interface'; +import { ContextProp, DateData, MarkedDates, Theme } from '../types'; import BasicDay from './day/basic'; +import Day, { DayProps } from './day/index'; +import CalendarHeader, { CalendarHeaderProps } from './header'; +import styleConstructor from './style'; export interface CalendarProps extends CalendarHeaderProps, DayProps { /** Specify theme properties to override specific styles for calendar parts */ @@ -94,10 +97,14 @@ const Calendar = (props: CalendarProps & ContextProp) => { style: propsStyle } = props; const [currentMonth, setCurrentMonth] = useState(current || initialDate ? parseDate(current || initialDate) : new XDate()); - const style = useRef(styleConstructor(theme)); + const [style, setStyle] = useState(styleConstructor(theme)); const header = useRef(); const weekNumberMarking = useRef({disabled: true, disableTouchEvent: true}); + useEffect(() => { + setStyle(styleConstructor(theme)); +}, [theme]); + useEffect(() => { if (initialDate) { setCurrentMonth(parseDate(initialDate)); @@ -174,7 +181,7 @@ const Calendar = (props: CalendarProps & ContextProp) => { const renderWeekNumber = (weekNumber: number) => { return ( - + { const renderDay = (day: XDate, id: number) => { if (!sameMonth(day, currentMonth) && hideExtraDays) { - return ; + return ; } const dayProps = extractDayProps(props); @@ -198,7 +205,7 @@ const Calendar = (props: CalendarProps & ContextProp) => { const disableDaySelection = isEmpty(props.context); return ( - + { } return ( - + {week} ); @@ -239,7 +246,7 @@ const Calendar = (props: CalendarProps & ContextProp) => { weeks.push(renderWeek(days.splice(0, 7), weeks.length)); } - return {weeks}; + return {weeks}; }; const shouldDisplayIndicator = useMemo(() => { @@ -280,7 +287,7 @@ const Calendar = (props: CalendarProps & ContextProp) => { return (