Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/calendar-list/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ export interface CalendarListProps extends CalendarProps, Omit<FlatListProps<any
showScrollIndicator?: boolean;
/** Whether to animate the auto month scroll */
animateScroll?: boolean;
/** Placeholder rendered when the month is loading. */
renderPlaceholder?: (year?: number, month?: number) => JSX.Element;
}

export interface CalendarListImperativeMethods {
Expand Down Expand Up @@ -80,6 +82,7 @@ const CalendarList = (props: CalendarListProps & ContextProp, ref: any) => {
animateScroll = false,
showScrollIndicator = false,
staticHeader,
renderPlaceholder,
/** View props */
testID,
style: propsStyle,
Expand Down Expand Up @@ -240,6 +243,7 @@ const CalendarList = (props: CalendarListProps & ContextProp, ref: any) => {
calendarHeight={calendarHeight}
scrollToMonth={scrollToMonth}
visible={isDateInRange(item)}
renderPlaceholder={renderPlaceholder}
/>
);
}, [horizontal, calendarStyle, calendarWidth, testID, getMarkedDatesForItem, isDateInRange, calendarProps]);
Expand Down
11 changes: 9 additions & 2 deletions src/calendar-list/item.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import XDate from 'xdate';
import React, {useRef, useMemo, useCallback} from 'react';
import {Text} from 'react-native';
import {Text, View} from 'react-native';
import {Theme} from '../types';
import {toMarkingFormat} from '../interface';
import {extractCalendarProps} from '../componentUpdater';
Expand All @@ -15,6 +15,7 @@ export type CalendarListItemProps = CalendarProps & {
theme?: Theme;
scrollToMonth?: (date: XDate) => void;
visible?: boolean;
renderPlaceholder?: (year?: number, month?: number) => JSX.Element;
};

const CalendarListItem = React.memo((props: CalendarListItemProps) => {
Expand All @@ -29,7 +30,8 @@ const CalendarListItem = React.memo((props: CalendarListItemProps) => {
headerStyle,
onPressArrowLeft,
onPressArrowRight,
visible
visible,
renderPlaceholder
} = props;

const style = useRef(styleConstructor(theme));
Expand Down Expand Up @@ -82,6 +84,11 @@ const CalendarListItem = React.memo((props: CalendarListItemProps) => {
}, [onPressArrowRight, scrollToMonth]);

if (!visible) {
if (renderPlaceholder) {
const year = item.getFullYear();
const month = item.getMonth();
return <View style={calendarStyle}>{renderPlaceholder(year, month)}</View>;
}
return (
<Text style={textStyle}>{dateString}</Text>
);
Expand Down