React-native-calendars: Change background color of selected dates

Created on 11 Mar 2019  路  1Comment  路  Source: wix/react-native-calendars

I want to change the selected Day background color, but in circle form instead of period.

Most helpful comment

if you hold the selected date in state, then onDayPress you can pass the selected day object into that state and then it will show up.

Here's an example:

constructor(props) {
super(props);
this.state = {
dateSelected: ''
};
}


<Calendar
onDayPress={(day) => {
this.setState({
dateSelected:{[day.dateString]:{selected: true, selectedColor: '#466A8F'}}
},() => {
console.log(this.state.dateSelected)
})
}}

//set the state of the day you are selecting. It has to be an object like above because the 'markedDates' property is expecting an object.

markedDates={this.state.dateSelected}

//Pass in the selected date state as seen above. You can customize the properties of the date when you save the state onDayPress.

>All comments

if you hold the selected date in state, then onDayPress you can pass the selected day object into that state and then it will show up.

Here's an example:

constructor(props) {
super(props);
this.state = {
dateSelected: ''
};
}


<Calendar
onDayPress={(day) => {
this.setState({
dateSelected:{[day.dateString]:{selected: true, selectedColor: '#466A8F'}}
},() => {
console.log(this.state.dateSelected)
})
}}

//set the state of the day you are selecting. It has to be an object like above because the 'markedDates' property is expecting an object.

markedDates={this.state.dateSelected}

//Pass in the selected date state as seen above. You can customize the properties of the date when you save the state onDayPress.
Was this page helpful?
0 / 5 - 0 ratings

Related issues

idlework picture idlework  路  4Comments

joaosauer picture joaosauer  路  4Comments

AleksandrZhukov picture AleksandrZhukov  路  3Comments

henrikra picture henrikra  路  3Comments

akhilsanker picture akhilsanker  路  4Comments