Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor expandable calendar to have a configurable week height #2436

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
12 changes: 10 additions & 2 deletions src/expandableCalendar/expandableCalendar.api.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
"images": [
"https://github.com/wix/react-native-calendars/blob/master/demo/assets/expandable-calendar.gif?raw=true"
],
"extends": ["CalendarList"],
"extends": [
"CalendarList"
],
"extendsLink": [
"https://github.com/wix/react-native-calendars/blob/master/src/calendar-list/index.tsx"
],
Expand Down Expand Up @@ -70,6 +72,12 @@
"type": "boolean",
"description": "Whether to close the calendar on day press",
"default": "true"
},
{
"name": "weekHeight",
"type": "number",
"description": "Overrides the default value for a week's row height",
"default": "46"
}
]
}
}
5 changes: 4 additions & 1 deletion src/expandableCalendar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ export interface ExpandableCalendarProps extends CalendarListProps {
closeThreshold?: number;
/** Whether to close the calendar on day press. Default = true */
closeOnDayPress?: boolean;
/** overrides the default week height */
weekHeight?: number;
}

const headerStyleOverride = {
Expand Down Expand Up @@ -109,6 +111,7 @@ const ExpandableCalendar = (props: ExpandableCalendarProps) => {
openThreshold = PAN_GESTURE_THRESHOLD,
closeThreshold = PAN_GESTURE_THRESHOLD,
closeOnDayPress = true,
weekHeight = WEEK_HEIGHT,

/** CalendarList props */
horizontal = true,
Expand Down Expand Up @@ -175,7 +178,7 @@ const ExpandableCalendar = (props: ExpandableCalendarProps) => {
if (!horizontal) {
return Math.max(constants.screenHeight, constants.screenWidth);
}
return CLOSED_HEIGHT + (WEEK_HEIGHT * (numberOfWeeks.current - 1)) + (hideKnob ? 12 : KNOB_CONTAINER_HEIGHT) + (constants.isAndroid ? 3 : 0);
return CLOSED_HEIGHT + (weekHeight * (numberOfWeeks.current - 1)) + (hideKnob ? 12 : KNOB_CONTAINER_HEIGHT) + (constants.isAndroid ? 3 : 0);
};
const openHeight = useRef(getOpenHeight());
const closedHeight = useMemo(() => CLOSED_HEIGHT + (hideKnob || Number(numberOfDays) > 1 ? 0 : KNOB_CONTAINER_HEIGHT), [numberOfDays, hideKnob]);
Expand Down