UNPKG

react-native-full-calendars

Version:

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

69 lines (68 loc) 1.83 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.useSwiperController = useSwiperController; var _react = require("react"); var _reactNativeReanimated = require("react-native-reanimated"); var _store = require("../store"); function useSwiperController(ctrOptions) { const { props } = (0, _react.useContext)(_store.SwiperContext); const { minIndex, maxIndex, initialIndex = 0, onPageChange } = props; const { layoutPage, viewSize, translate, pageAnim } = ctrOptions; const [currentIndex, setCurrentIndex] = (0, _react.useState)(initialIndex); const onPageChangeInternal = pg => { onPageChange?.(pg); setCurrentIndex(pg); }; (0, _reactNativeReanimated.useAnimatedReaction)(() => { return Math.round(pageAnim.value); }, (cur, prev) => { if (cur !== prev) { (0, _reactNativeReanimated.runOnJS)(onPageChangeInternal)(cur); } }, []); const setPage = (index, options = {}) => { const pSize = viewSize.value || layoutPage; const updatedTranslate = index * pSize * -1 + initialIndex * pSize; if (index < minIndex || index > maxIndex) { return; } if (options.animated) { translate.value = (0, _reactNativeReanimated.withTiming)(updatedTranslate, { duration: 500, easing: _reactNativeReanimated.Easing.bezier(0.25, 1, 0.5, 1) }); } else { translate.value = updatedTranslate; } }; const nextPage = async (options = {}) => { setPage(getCurrIndex() + 1, options); }; const prevPage = async (options = {}) => { setPage(getCurrIndex() - 1, options); }; const getCurrIndex = () => { return currentIndex; }; return { setPage, getCurrIndex, nextPage, prevPage }; } //# sourceMappingURL=useSwiperController.js.map