Skip to content

Custom style for separator between customer day cells. #2709

@Cicko

Description

@Cicko

Hi there!

I am trying to achieve this design:

Image

But when I use a custom dayComponent I don't know how to set the style of the spaces between the days, to set the correct background color. Maybe am I taking a wrong approach?

Currently it looks like this:

Image

Regarding the code (the important parts) basically looks like this:

import { CalendarList } from "react-native-calendars";

export const RangeDateTimePicker: React.FC<RangeDateTimePickerProps> = ({

    const markedDates = useMemo(() => {
        if (!selectedFrom || !selectedTo) {
            return {};
        }

        const range = eachDayOfInterval({
            start: selectedFrom,
            end: selectedTo,
        });

        const marked = range.reduce(
            (acc, date, index) => {
                const dateString = transformDateToMarkedDateString(date);

                acc[dateString] = {
                    type: "period",
                    selected: true,
                    textColor: "black",
                    startingDay: index === 0,
                    endingDay: index === range.length - 1,
                };

                return acc;
            },
            {} as Record<string, MarkingProps>,
        );

        return marked;
    }, [selectedFrom, selectedTo]);

    const dayCellRenderer = useCallback(
        ({
            date,
            state,
            marking,
        }: DayProps & {
            date?: DateData | undefined;
        }) => <DayCell date={date} state={state} marking={marking} onDayPress={onDayPress} />,
        [],
    );

    const itemSeparatorRenderer = useCallback(
        ({
            date,
            state,
            marking,
        }: DayProps & {
            date?: DateData | undefined;
         // This item simply sets the background to blue
        }) => <ItemSeparator date={date} state={state} marking={marking}  />,
        [],
    );

  return (
    <CalendarList
        markingType="period"
        minDate={minDate && minDate.toISOString()}
        pastScrollRange={pastScrollRange}
        futureScrollRange={18}
        markedDates={markedDates}
        hideDayNames={true}
        maxToRenderPerBatch={1}
        initialNumToRender={2}
        style={styles.calendar}
        calendarStyle={styles.calendarStyle}
        theme={{
            monthTextColor: theme.colors.typography,
            dayTextColor: "transparent",
            textSectionTitleColor: "#b6c1cd",
        }}
        dayComponent={dayCellRenderer}
        // This component is not rendered :(
        ItemSeparatorComponent={itemSeparatorRenderer}
    />
  );

}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions