UNPKG

react-native-text-plus

Version:
84 lines (83 loc) 3.4 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = exports.TextContextProvider = exports.TextContext = exports.Text = exports.Provider = exports.Context = void 0; var _reactNative = require("react-native"); var _maskedView = _interopRequireDefault(require("@react-native-masked-view/masked-view")); var _reactNativeLinearGradient = _interopRequireDefault(require("react-native-linear-gradient")); var _react = require("react"); var _jsxRuntime = require("react/jsx-runtime"); function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; } const textStylePick = ['color', 'fontFamily', 'fontSize', 'fontStyle', 'fontWeight', 'letterSpacing', 'lineHeight', 'textAlign', 'textDecorationLine', 'textDecorationStyle', 'textDecorationColor', 'textShadowColor', 'textShadowOffset', 'textShadowRadius', 'textTransform', 'userSelect', 'textAlignVertical', 'verticalAlign', 'includeFontPadding', 'fontVariant', 'writingDirection']; const textPropsPick = ['allowFontScaling']; const linearGradientPropsPick = ['colors', 'start', 'end', 'locations', 'useAngle', 'angleCenter', 'angle']; const TextContext = exports.TextContext = /*#__PURE__*/(0, _react.createContext)({}); const Provider = ({ children, value }) => { const preContext = (0, _react.useContext)(TextContext); return /*#__PURE__*/(0, _jsxRuntime.jsx)(TextContext.Provider, { value: { ...preContext, ...value }, children: children }); }; exports.Provider = Provider; const TextContextProvider = exports.TextContextProvider = Provider; const Context = exports.Context = TextContext; const Text = props => { const context = (0, _react.useContext)(TextContext); const textProps = { ...omitObj(context, textStylePick), ...omitObj(props, textStylePick, linearGradientPropsPick), style: { ...pickObj(context, textStylePick), ...pickObj(props, textStylePick), ...props.style } }; return /*#__PURE__*/(0, _jsxRuntime.jsx)(Provider, { value: { ...context, ...pickObj(props, textStylePick) }, children: props.colors ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, { children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_maskedView.default, { style: { flex: 0 }, maskElement: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, { ...textProps, style: { ...textProps.style, backgroundColor: 'transparent', color: '#000' } }), children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNativeLinearGradient.default, { ...pickObj(props, linearGradientPropsPick), children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, { ...textProps, style: { ...textProps.style, opacity: 0 } }) }) }) }) : /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, { ...textProps }) }); }; exports.Text = Text; Text.Provider = Provider; Text.Context = TextContext; var _default = exports.default = Text; const omitObj = (obj, ...keys) => Object.fromEntries(Object.entries(obj).filter(([k]) => !keys.flat().includes(k))); const pickObj = (obj, ...keys) => Object.fromEntries(Object.entries(obj).filter(([k]) => keys.flat().includes(k))); //# sourceMappingURL=index.js.map