Calendar did not update marking date after select
See original GitHub issueI want to use this calendar for my app with range select. My solution is:
- Users first select date to mark it
from date
. (startingdate) - User select second date to mark it
to date
. (endingdate) - Then the date between them also marked.
here is my code:
constructor(props) {
super(props);
this.state = {
isFromDatePicked: false,
isToDatePicked: false,
FromDate: '',
ToDate: '',
markedDates: {}
};
}
onDayPress(day) {
let markedDates = this.state.markedDates;
if(this.state.isFromDatePicked == false){
markedDates[day.dateString] = [{startingDay: true, color: '#AED8D6'}];
console.log(markedDates);
this.setState({
isFromDatePicked: true,
FromDate: day.dateString,
markedDates: markedDates
});
}else {
//Check if toDate not yet check
if(this.state.isToDatePicked == false){//not checked yet
let fromDate = new XDate(this.state.FromDate);
let toDate = new XDate(day.dateString);
let range = fromDate.diffDays(toDate);
if( range> 0){
for (var i = 1; i <= range; i++) {
//let tempFromDate = fromDate;
let tempDate = fromDate.addDays(1);
if(i < range){
markedDates[tempDate.toString('yyyy-MM-dd')] = [{ color: '#AED8D6'}];
}else{
markedDates[tempDate.toString('yyyy-MM-dd')] = [{endingDay: true, color: '#AED8D6'}];
}
}
this.setState({
isToDatePicked: true,
ToDate: day.dateString,
markedDates: markedDates
});
}else{
alert('To Date must greater than From Date');
}
}else{
//do nothing
}
}
}
<Calendar
minDate={new XDate()}
onDayPress={(day) => {this.onDayPress(day)}}
style={styles.calendar}
hideExtraDays
markedDates={this.state.markedDates}
markingType={'interactive'}
/>
This code seem to be work fine as it logic, but the UI did not change immediate, i must press the arrow to go to next month and press arrow back to see the UI updated. What about the missing code here to update the UI? Or can we use a trigger to update UI after select dates?
Issue Analytics
- State:
- Created 6 years ago
- Reactions:5
- Comments:5 (1 by maintainers)
Top Results From Across the Web
State Changed But View Not Updating React Native
I am using 'react-native-calendars' .My Goal is to display dots and then mark multiple dates on users press. Marking dots is a success....
Read more >Use conditional formatting to give your calendar a visual refresh
Use conditional formatting to give your calendar a visual refresh · From your Calendar folder, select View > View Settings. · Select Conditional...
Read more >How do I update my calendar? - Love Home Swap - HappyFox
Click on the date range you'd like to add availability to. This will bring up a window that summarises the dates you've selected...
Read more >Check and update your calendar on Apple Watch
See calendar events on Apple Watch. Open the Calendar app on your Apple Watch, or tap the date or a calendar event on...
Read more >Manage repeating tasks in Google Tasks & Google Calendar
Open the Google Calendar app Calendar . · Tap an existing task or create a new task. · Tap Edit Edit . ·...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
let markedDates = {…this.state.markedDates} should fix your problem
Base on @sonnguyenit code I created https://github.com/lazaronixon/react-native-date-range-picker