question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Calendar did not update marking date after select

See original GitHub issue

I 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:closed
  • Created 6 years ago
  • Reactions:5
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

4reactions
shapovalstascommented, Oct 17, 2017

let markedDates = {…this.state.markedDates} should fix your problem

0reactions
lazaronixoncommented, Mar 27, 2018
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found