Selected dates are not shown as colored-period
Please make our job easier by filling this template out to completion. If you're requesting a feature instead of reporting a bug, please feel free to skip the Environment and Reproducible Demo sections.
Description
First 9 days of the month is not colored as expected
Expected Behavior
I change the dates in calendar but they are not colored.. just first 9 days of the month
Observed Behavior
Only days after 9th days are colored
Environment
Please run these commands in the project folder and fill in their results:
npm ls react-native-calendars: [email protected]npm ls react-native: [email protected]
Codes:
<Calendar
firstDate={1}
markedDates={this.computeMarkedDates( this.state.startDate, this.state.finishDate )}
markingType={this.props.flightType === 0 ? 'multi-dot' : 'period'}
minDate={this.getStyledDateYMD(new Date().valueOf())}
onDayPress={this.calendarDayPressed}
/>
calendarDayPressed = (day) => {
//console.log(this.state.openFor);
//console.log(day.timestamp +"<"+ this.state.startDate);
//console.log(day.timestamp +">"+ this.state.finishDate);
if(this.props.flightType === 0){
this.setState({startDate: day.timestamp});
}
else{
if(this.state.calender === 1){
if(day.timestamp < this.state.startDate){
//console.log("küçükse");
this.setState({ startDate: day.timestamp });
}else if(day.timestamp > this.state.finishDate){
//console.log("büyükse");
this.setState({ startDate: this.state.finishDate, finishDate: day.timestamp + 24*60*60*1000*5 });
}else{
this.setState({ startDate: day.timestamp });
}
}else{
if(day.timestamp < this.state.startDate){
//this.setState({ finishDate: this.state.startDate, startDate: day.timestamp });
}else{
this.setState({ finishDate: day.timestamp });
}
}
}
}
computeMarkedDates = ( start, end ) => {
if(this.props.flightType === 0){
const markedDates = {
};
markedDates[this.getStyledDateYMD(start)] = {selected: true, marked: true, selectedColor: 'darkblue'}
return markedDates;
}
if(this.props.flightType === 1){
const markedDates = {
};
let j = 0;
let g = (end - start) / (24*60*60*1000);
for(let i = start; i <= end; i=i+(24*60*60*1000)){
if(j==0)
markedDates[this.getStyledDateYMD(i)] = { startingDay: true, color: 'darkblue', textColor: 'rgb(255, 255, 255)' }
else if(j == g)
markedDates[this.getStyledDateYMD(i)] = { endingDay: true, color: 'darkblue', textColor: 'rgb(255, 255, 255)' }
else
markedDates[this.getStyledDateYMD(i)] = { color: 'green', textColor: 'rgb(255, 255, 255)' }
j++;
}
return markedDates;
}
}
getStyledDateYMD = ( timestamp ) => {
const date = new Date(timestamp).getDate();
const month = parseInt(new Date(timestamp).getMonth() + 1);
return new Date(timestamp).getFullYear() + '-' + month + '-' + date ;
}
I just created a PR to have days in the period marking style set a background color on their container when selected: true. I think this may fix your issue.
https://github.com/wix/react-native-calendars/pull/827
Do you still have a problem?