Coder Social home page Coder Social logo

Comments (5)

tautvilas avatar tautvilas commented on May 5, 2024 2

Please try this:

selecionarData = (day) => {        
    const {datesMarked} = this.state;
    datesMarked =  {...datesMarked,  [day.dateString]: [{startingDay: true, color: '#42aaf4', selected: true}, {selected: true, endingDay: true, color: '#42aaf4', textColor: 'white'}]};
    this.setState({datesMarked: datesMarked})
}

Make sure that datesMarkes is not being mutated, but treated as immutable variable (so on each change it is being initialized again)

from react-native-calendars.

tautvilas avatar tautvilas commented on May 5, 2024

Hi, can you paste code of onDayPress ?

from react-native-calendars.

vagnerSl avatar vagnerSl commented on May 5, 2024

onDayPress(day) { this.props.selecionarData(day); }

selecionarData = (day) => {        
    const {datesMarked} = this.state;
    datesMarked[day.dateString]=  [{startingDay: true, color: '#42aaf4', selected: true}, {selected: true, endingDay: true, color: '#42aaf4', textColor: 'white'}];
    this.setState({datesMarked: datesMarked})
}

from react-native-calendars.

vagnerSl avatar vagnerSl commented on May 5, 2024

thanks !

from react-native-calendars.

AkshitSahani avatar AkshitSahani commented on May 5, 2024

Hi, I'm encountering the exact same problem. The background color for the dates is not changing unless I press the left or right arrow key to change month.

<Calendar
style={{marginTop: 70}}
minDate={getDate()}
maxDate={getDate('max')}
hideExtraDays={true}
onDayPress={(day)=>{this.selectDate(day)}}
markedDates={this.state.selectedDates}
onMonthChange={(month)=>{this.nextMonth(month);}}
/>

selectDate = (day) => {
const {tappedDates} = this.state;
let updatedTappedDates = {...tappedDates};
if(updatedTappedDates[day.dateString] && updatedTappedDates[day.dateString] < 2){
updatedTappedDates[day.dateString] += 1;
}
else if(updatedTappedDates[day.dateString] === 2){
updatedTappedDates[day.dateString] = 0;
}
else{
updatedTappedDates[day.dateString] = 1;
}

let color;
const calGreen = "#BFE9E6";
const calYellow = "#FBDC98";
const calRed = "#E7808D";

switch (updatedTappedDates[day.dateString]) {
  case 0:
    color = calGreen;
    break;
  case 1:
    color = calYellow;
    break;
  case 2:
    color = calRed;
    break;
  default:
    color = calGreen;
}

// const {selectedDates} = this.state;
// selectedDates = {...selectedDates, [day.dateString]: {selected: true, selectedColor: 'orange'}};
-------if i write these two lines above, based on the solution you provided to vagnerSI, I get an 
            error saying "selectedDates is read-only"-------

// const {selectedDates} = this.state;
// let newSelectedDates = {...selectedDates, [day.dateString]: {selected: true, selectedColor: 
    color}};
          ---- I tried this solution as well but not successful-------

let selectedDates = Object.assign({}, this.state.selectedDates);
selectedDates[day.dateString] = {selected: true, selectedColor: color};
this.setState({selectedDates: selectedDates});
 ------ I tried this solution as well after looking at some of your answers to other people having the 
            same problem, but this one is not successful either ----

};

from react-native-calendars.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.