UNPKG

@kirz/react-native-toolkit

Version:

Toolkit to speed up React Native development

134 lines 7.34 kB
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } import MaskedView from '@react-native-masked-view/masked-view'; import React, { useMemo } from 'react'; import { StyleSheet, View as ViewBase } from 'react-native'; import { BlurView } from './BlurView'; import { ViewInsetShadow } from './ViewInsetShadow'; import { ViewSkeleton } from './ViewSkeleton'; import { renderGradient } from '../utils/renderGradient'; export function View(_ref) { let { style, children, skeleton, skeletonStyle, ...props } = _ref; const { backgroundGradient: backgroundGradientProp, borderGradient: borderGradientProp, backgroundBlur, backgroundBlurProps, insetShadow, ...flattenStyle } = useMemo(() => StyleSheet.flatten(style) ?? {}, [style]); const flattenSkeletonStyle = useMemo(() => StyleSheet.flatten(skeletonStyle) ?? {}, [skeletonStyle]); const backgroundGradients = !backgroundGradientProp ? [] : typeof backgroundGradientProp === 'function' ? [backgroundGradientProp] : 'length' in backgroundGradientProp ? backgroundGradientProp : [backgroundGradientProp]; const borderGradients = !borderGradientProp ? [] : typeof borderGradientProp === 'function' ? [borderGradientProp] : 'length' in borderGradientProp ? borderGradientProp : [borderGradientProp]; const baseStyle = { position: 'absolute', left: 0, top: 0, right: 0, bottom: 0 }; const borderRadiusStyle = { borderBottomLeftRadius: flattenStyle.borderBottomLeftRadius ?? flattenStyle.borderRadius ?? 0, borderBottomRightRadius: flattenStyle.borderBottomRightRadius ?? flattenStyle.borderRadius ?? 0, borderTopLeftRadius: flattenStyle.borderTopLeftRadius ?? flattenStyle.borderRadius ?? 0, borderTopRightRadius: flattenStyle.borderTopRightRadius ?? flattenStyle.borderRadius ?? 0 }; const borderWidthStyle = { borderLeftWidth: flattenStyle.borderLeftWidth ?? flattenStyle.borderWidth ?? 0, borderRightWidth: flattenStyle.borderRightWidth ?? flattenStyle.borderWidth ?? 0, borderBottomWidth: flattenStyle.borderBottomWidth ?? flattenStyle.borderWidth ?? 0, borderTopWidth: flattenStyle.borderTopWidth ?? flattenStyle.borderWidth ?? 0 }; const innerBorderRadiusStyle = insetShadow && { borderBottomLeftRadius: borderRadiusStyle.borderBottomLeftRadius - (Math.max(borderWidthStyle.borderLeftWidth, borderWidthStyle.borderBottomWidth) ?? 0), borderBottomRightRadius: borderRadiusStyle.borderBottomRightRadius - (Math.max(borderWidthStyle.borderRightWidth, borderWidthStyle.borderBottomWidth) ?? 0), borderTopLeftRadius: borderRadiusStyle.borderTopLeftRadius - (Math.max(borderWidthStyle.borderLeftWidth, borderWidthStyle.borderTopWidth) ?? 0), borderTopRightRadius: borderRadiusStyle.borderTopRightRadius - (Math.max(borderWidthStyle.borderRightWidth, borderWidthStyle.borderTopWidth) ?? 0) }; const borderColorStyle = { borderLeftColor: flattenStyle.borderLeftColor ?? flattenStyle.borderColor, borderRightColor: flattenStyle.borderRightColor ?? flattenStyle.borderColor, borderTopColor: flattenStyle.borderTopColor ?? flattenStyle.borderColor, borderBottomColor: flattenStyle.borderBottomColor ?? flattenStyle.borderColor }; const borderWidthNegativeStyle = { marginLeft: -(flattenStyle.borderLeftWidth ?? flattenStyle.borderWidth ?? 0), marginRight: -(flattenStyle.borderRightWidth ?? flattenStyle.borderWidth ?? 0), marginTop: -(flattenStyle.borderTopWidth ?? flattenStyle.borderWidth ?? 0), marginBottom: -(flattenStyle.borderBottomWidth ?? flattenStyle.borderWidth ?? 0) }; const renderAbsolute = (content, borderAdjust, isSkeletonView) => { return /*#__PURE__*/React.createElement(ViewBase, { style: [borderAdjust ? { position: 'absolute', left: borderWidthStyle.borderLeftWidth > 0 ? 1 : 0, top: borderWidthStyle.borderTopWidth > 0 ? 1 : 0, right: borderWidthStyle.borderRightWidth > 0 ? 1 : 0, bottom: borderWidthStyle.borderBottomWidth > 0 ? 1 : 0 } : baseStyle, ...(!isSkeletonView && skeleton ? [{ opacity: 0 }] : [])], pointerEvents: "none" }, /*#__PURE__*/React.createElement(ViewBase, { style: [{ flex: 1, overflow: 'hidden' }, borderRadiusStyle, borderWidthNegativeStyle] }, content)); }; return /*#__PURE__*/React.createElement(ViewBase, _extends({}, props, { style: [flattenStyle] }), backgroundGradients.length > 0 && renderAbsolute(renderGradient(backgroundGradients), true), backgroundBlur && renderAbsolute( /*#__PURE__*/React.createElement(ViewBase, { style: [baseStyle, borderColorStyle, borderRadiusStyle, borderWidthStyle, { borderColor: 'transparent' }] }, /*#__PURE__*/React.createElement(BlurView, _extends({}, backgroundBlurProps, { style: [{ flex: 1 }, backgroundBlurProps === null || backgroundBlurProps === void 0 ? void 0 : backgroundBlurProps.style], blurType: (backgroundBlurProps === null || backgroundBlurProps === void 0 ? void 0 : backgroundBlurProps.blurType) ?? backgroundBlur })))), insetShadow && /*#__PURE__*/React.createElement(ViewInsetShadow, _extends({}, insetShadow, { wrapperProps: { style: [{ position: 'absolute', left: 0, right: 0, top: 0, bottom: 0, overflow: 'hidden' }, innerBorderRadiusStyle] }, style: [baseStyle], innerBorderRadiusStyle: innerBorderRadiusStyle })), backgroundGradients.length > 0 && !borderGradients.length && renderAbsolute( /*#__PURE__*/React.createElement(ViewBase, { style: [baseStyle, borderColorStyle, borderRadiusStyle, borderWidthStyle] })), borderGradients.length > 0 && renderAbsolute( /*#__PURE__*/React.createElement(MaskedView, { style: baseStyle, maskElement: /*#__PURE__*/React.createElement(View, { style: [baseStyle, borderRadiusStyle, borderWidthStyle] }) }, renderGradient(borderGradients))), skeleton ? /*#__PURE__*/React.createElement(View, { style: { opacity: 0 } }, children) : children, skeleton && /*#__PURE__*/React.createElement(ViewSkeleton, { style: [{ position: 'absolute', left: -1, top: -1, right: -1, bottom: -1 }, skeletonStyle, { borderBottomLeftRadius: flattenSkeletonStyle.borderBottomLeftRadius ?? flattenStyle.borderBottomLeftRadius ?? flattenSkeletonStyle.borderRadius ?? flattenStyle.borderRadius ?? 0, borderBottomRightRadius: flattenSkeletonStyle.borderBottomRightRadius ?? flattenStyle.borderBottomRightRadius ?? flattenSkeletonStyle.borderRadius ?? flattenStyle.borderRadius ?? 0, borderTopLeftRadius: flattenSkeletonStyle.borderTopLeftRadius ?? flattenStyle.borderTopLeftRadius ?? flattenSkeletonStyle.borderRadius ?? flattenStyle.borderRadius ?? 0, borderTopRightRadius: flattenSkeletonStyle.borderTopRightRadius ?? flattenStyle.borderTopRightRadius ?? flattenSkeletonStyle.borderRadius ?? flattenStyle.borderRadius ?? 0 }] })); } //# sourceMappingURL=View.js.map