acro5piano / react-native-big-calendar

gcal/outlook like calendar component for React Native
https://react-native-big-calendar.vercel.app
MIT License
445 stars 149 forks source link

How to change the background color of the event Cells. #735

Closed chinmay4github1987 closed 2 years ago

chinmay4github1987 commented 2 years ago

I am using the below code to change the background color of calendar cells with the eventCellStyle prop, but not getting the colors.

<Calendar
        // ampm={true}
        theme={darkTheme}
        eventCellStyle ={renderCustomEvent(new_events)}
        mode={'month'}
        hideNowIndicator={false}
        startAccessor="start"
        endAccessor="end"
        events={new_events}
        // defaultDate={moment().toDate()}
        height={600}
        swipeEnabled={false}
        showAdjacentMonths={false}
        // defaultDate={date}
        // renderEvent={renderNewEvents()}
        date={date}
      />

  const renderCustomEvent = (eventItem) => {
     const backgroundColor = eventItem.attended ? 'green' : 'red';
     return { style: { backgroundColor } }
  }
acro5piano commented 2 years ago

Your code is wrong. The code should be something like this:

<Calendar
        // ampm={true}
        theme={darkTheme}
        eventCellStyle ={renderCustomEvent}  // <------------ here
        mode={'month'}
        hideNowIndicator={false}
        startAccessor="start"
        endAccessor="end"
        events={new_events}
        // defaultDate={moment().toDate()}
        height={600}
        swipeEnabled={false}
        showAdjacentMonths={false}
        // defaultDate={date}
        // renderEvent={renderNewEvents()}
        date={date}
      />

  const renderCustomEvent = (eventItem) => {
     const backgroundColor = eventItem.attended ? 'green' : 'red';
     return { backgroundColor } // <------------ here
  }