Skip to content

change week and day keys to unique values to prevent collisions when switching months #2695

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions src/calendar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -188,17 +188,19 @@ const Calendar = (props: CalendarProps & ContextProp) => {
);
};

const renderDay = (day: XDate, id: number) => {
const renderDay = (day: XDate) => {
const key = `${currentMonth.toISOString()}-${day.getDate()}`;

if (!sameMonth(day, currentMonth) && hideExtraDays) {
return <View key={id} style={style.current.emptyDayContainer}/>;
return <View key={key} style={style.current.emptyDayContainer}/>;
}

const dayProps = extractDayProps(props);
const dateString = toMarkingFormat(day);
const disableDaySelection = isEmpty(props.context);

return (
<View style={style.current.dayContainer} key={id}>
<View style={style.current.dayContainer} key={key}>
<Day
{...dayProps}
testID={`${testID}.day_${dateString}`}
Expand All @@ -212,19 +214,20 @@ const Calendar = (props: CalendarProps & ContextProp) => {
);
};

const renderWeek = (days: XDate[], id: number) => {
const renderWeek = (days: XDate[]) => {
const week: JSX.Element[] = [];
const key = `${currentMonth.toISOString()}-${days[0].getDate()}`;

days.forEach((day: XDate, id2: number) => {
week.push(renderDay(day, id2));
days.forEach((day: XDate) => {
week.push(renderDay(day));
}, this);

if (props.showWeekNumbers) {
week.unshift(renderWeekNumber(days[days.length - 1].getWeek()));
}

return (
<View style={style.current.week} key={id}>
<View style={style.current.week} key={key}>
{week}
</View>
);
Expand All @@ -236,7 +239,7 @@ const Calendar = (props: CalendarProps & ContextProp) => {
const weeks: JSX.Element[] = [];

while (days.length) {
weeks.push(renderWeek(days.splice(0, 7), weeks.length));
weeks.push(renderWeek(days.splice(0, 7)));
}

return <View style={style.current.monthView}>{weeks}</View>;
Expand Down