UNPKG

react-native-full-calendars

Version:

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

84 lines (83 loc) 3.45 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _dateFns = require("date-fns"); var _react = _interopRequireWildcard(require("react")); var _reactNative = require("react-native"); var _Swiper = _interopRequireDefault(require("../../swiper/components/Swiper")); var _useCalendarController = require("../hooks/useCalendarController"); var _store = require("../store"); var _Month = require("./month/Month"); var _jsxRuntime = require("react/jsx-runtime"); function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; } function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); } function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; } const Calendar = /*#__PURE__*/_react.default.forwardRef((_, ref) => { const { onPageChange, buffer, minDate, maxDate, theme, initialDate } = (0, _react.useContext)(_store.CalendarContext); const swiperRef = (0, _react.useRef)(null); const minSwiperIndex = (0, _react.useMemo)(() => { if (!minDate) { return -Infinity; } return (0, _dateFns.differenceInCalendarMonths)(initialDate, minDate) * -1; }, [minDate, initialDate]); const maxSwiperIndex = (0, _react.useMemo)(() => { if (!maxDate) { return Infinity; } return (0, _dateFns.differenceInCalendarMonths)(initialDate, maxDate) * -1; }, [maxDate, initialDate]); const onPageChangeRef = (0, _react.useRef)(onPageChange); onPageChangeRef.current = onPageChange; const { goToDatePage, goToNextPage, goToPrevPage } = (0, _useCalendarController.useCalendarController)({ swiperRef, initialDate }); (0, _react.useImperativeHandle)(ref, () => ({ goToDatePage, goToNextPage, goToPrevPage })); const onMonthChange = (0, _react.useCallback)(pg => { const offsetDate = (0, _dateFns.addMonths)(initialDate, pg); const startDateOfMonth = (0, _dateFns.startOfMonth)(offsetDate); onPageChangeRef.current?.(startDateOfMonth); }, [initialDate]); return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, { style: [styleSheet.flex, theme.style], children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_Swiper.default, { ref: swiperRef, renderPage: ({ index }) => /*#__PURE__*/(0, _jsxRuntime.jsx)(_Month.Month, { index: index }), buffer: buffer, onPageChange: onMonthChange, minIndex: minSwiperIndex, maxIndex: maxSwiperIndex, pageWrapperStyle: [styleSheet.flex, theme.containerStyle], style: styleSheet.flex }) }); }); var _default = exports.default = (0, _store.WithWrappedProvider)(Calendar); const styleSheet = _reactNative.StyleSheet.create({ flex: { flex: 1 } }); //# sourceMappingURL=Calendar.js.map