UNPKG

react-native-full-calendars

Version:

React Native Full Calendar (RNFC) is an intuitive and powerful calendar component library designed for React Native.

107 lines (106 loc) 2.65 kB
"use strict"; import { format, getDate, isSameDay } from 'date-fns'; import React, { useCallback, useContext, useMemo, useRef } from 'react'; import { StyleSheet, TouchableOpacity, View } from 'react-native'; import { CalendarContext } from '../../store'; import { Day } from './Day'; import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; const handleItems = items => { return items.map(v => { if (!v) { return null; } const { metadata: _metadata, ...data } = v; return data; }); }; export const DayWrapper = /*#__PURE__*/React.memo(({ date, isDisabled }) => { const dateRef = useRef(date); const memoDate = useMemo(() => { if (isSameDay(dateRef.current, date)) { return dateRef.current; } else { dateRef.current = date; return date; } }, [date]); const { selectedDate, onDatePress, renderDate, weekStartDay, dataMap, theme, renderMoreItemText, maxVisibleCount } = useContext(CalendarContext); const isSelected = useMemo(() => { return !!selectedDate && isSameDay(memoDate, selectedDate); }, [memoDate, selectedDate]); const isToday = useMemo(() => isSameDay(memoDate, new Date()), [memoDate]); const onDateSelectRef = useRef(onDatePress); onDateSelectRef.current = onDatePress; const onDateSelectCb = useCallback((_date, options) => { return onDateSelectRef.current?.(_date, options); }, []); const items = dataMap[format(date, 'yyyy-MM-dd')] || []; if (renderDate) { return renderDate({ date, isDisabled, isSelected, isToday, itemsWithMetadata: items, items: handleItems(items) }); } const onPress = () => { onDateSelectCb(date, { isSelected, isToday, isDisabled, items: handleItems(items), itemsWithMetadata: items }); }; const zIndex = 100 - getDate(date); return /*#__PURE__*/_jsxs(View, { style: [styleSheet.flex, { zIndex }], children: [/*#__PURE__*/_jsx(TouchableOpacity, { onPress: onPress, style: styleSheet.coverContainer }), /*#__PURE__*/_jsx(Day, { date: memoDate, isToday: isToday, isDisabled: isDisabled, theme: theme, items: items, weekStartDay: weekStartDay, renderMoreItemText: renderMoreItemText, maxVisibleCount: maxVisibleCount, isSelected: isSelected })] }); }); const styleSheet = StyleSheet.create({ flex: { flex: 1 }, coverContainer: { position: 'absolute', top: 0, left: 0, right: 0, bottom: 0, zIndex: 101 } }); //# sourceMappingURL=DayWrapper.js.map