UNPKG

react-native-full-calendars

Version:

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

65 lines (64 loc) 1.64 kB
"use strict"; import { useContext, useState } from 'react'; import { Easing, runOnJS, useAnimatedReaction, withTiming } from 'react-native-reanimated'; import { SwiperContext } from '../store'; export function useSwiperController(ctrOptions) { const { props } = useContext(SwiperContext); const { minIndex, maxIndex, initialIndex = 0, onPageChange } = props; const { layoutPage, viewSize, translate, pageAnim } = ctrOptions; const [currentIndex, setCurrentIndex] = useState(initialIndex); const onPageChangeInternal = pg => { onPageChange?.(pg); setCurrentIndex(pg); }; useAnimatedReaction(() => { return Math.round(pageAnim.value); }, (cur, prev) => { if (cur !== prev) { 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 = withTiming(updatedTranslate, { duration: 500, easing: 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