react-native-full-calendars
Version:
React Native Full Calendar (RNFC) is an intuitive and powerful calendar component library designed for React Native.
100 lines (98 loc) • 3.65 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.pageInterpolatorSlide = exports.Page = void 0;
var _react = _interopRequireWildcard(require("react"));
var _reactNative = require("react-native");
var _reactNativeReanimated = _interopRequireWildcard(require("react-native-reanimated"));
var _store = require("../store");
var _jsxRuntime = require("react/jsx-runtime");
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 preInitSize = (0, _reactNativeReanimated.makeMutable)(99999);
const Page = ({
index,
pageAnim,
pageWidth,
pageHeight,
isActive,
style,
viewSize
}) => {
const {
props
} = (0, _react.useContext)(_store.SwiperContext);
const {
buffer,
initialIndex,
vertical,
renderPage
} = props;
const translation = (0, _reactNativeReanimated.useDerivedValue)(() => {
const translate = (index - pageAnim.value) * viewSize.value;
return translate;
}, []);
const focusAnim = (0, _reactNativeReanimated.useDerivedValue)(() => {
if (!viewSize.value) {
return index - initialIndex;
}
return translation.value / viewSize.value;
}, [initialIndex]);
const animStyle = (0, _reactNativeReanimated.useAnimatedStyle)(() => {
const hasInitialized = !!viewSize.value;
const isInactivePageBeforeInit = !(index === initialIndex) && !hasInitialized;
const _pageWidth = isInactivePageBeforeInit ? preInitSize : pageWidth;
const _pageHeight = isInactivePageBeforeInit ? preInitSize : pageHeight;
return pageInterpolatorSlide({
focusAnim,
pageWidth: _pageWidth,
pageHeight: _pageHeight,
vertical
});
}, [pageWidth, pageHeight, pageAnim, index, initialIndex, translation, vertical, buffer]);
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNativeReanimated.default.View, {
pointerEvents: isActive ? 'auto' : 'none',
style: [style, styles.pageWrapper, animStyle, isActive && styles.activePage],
children: renderPage({
index,
isActive,
focusAnim,
pageWidthAnim: pageWidth,
pageHeightAnim: pageHeight,
pageAnim
})
});
};
exports.Page = Page;
const styles = _reactNative.StyleSheet.create({
pageWrapper: {
left: 0,
right: 0,
top: 0,
bottom: 0,
position: 'absolute'
},
activePage: {
position: 'relative'
}
});
const pageInterpolatorSlide = ({
focusAnim,
pageWidth,
pageHeight,
vertical
}) => {
'worklet';
const translateX = vertical ? 0 : (0, _reactNativeReanimated.interpolate)(focusAnim.value, [-1, 0, 1], [-pageWidth.value, 0, pageWidth.value]);
const translateY = vertical ? (0, _reactNativeReanimated.interpolate)(focusAnim.value, [-1, 0, 1], [-pageHeight.value, 0, pageHeight.value]) : 0;
return {
transform: [{
translateX
}, {
translateY
}]
};
};
exports.pageInterpolatorSlide = pageInterpolatorSlide;
//# sourceMappingURL=Page.js.map