react-native-text-plus
Version:
react-native-text-plus
77 lines (76 loc) • 2.73 kB
JavaScript
;
import { Text as RNText } from 'react-native';
import MaskedView from '@react-native-masked-view/masked-view';
import LinearGradient from 'react-native-linear-gradient';
import { createContext, useContext } from 'react';
import { jsx as _jsx } from "react/jsx-runtime";
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'];
export const TextContext = /*#__PURE__*/createContext({});
export const Provider = ({
children,
value
}) => {
const preContext = useContext(TextContext);
return /*#__PURE__*/_jsx(TextContext.Provider, {
value: {
...preContext,
...value
},
children: children
});
};
export const TextContextProvider = Provider;
export const Context = TextContext;
export const Text = props => {
const context = useContext(TextContext);
const textProps = {
...omitObj(context, textStylePick),
...omitObj(props, textStylePick, linearGradientPropsPick),
style: {
...pickObj(context, textStylePick),
...pickObj(props, textStylePick),
...props.style
}
};
return /*#__PURE__*/_jsx(Provider, {
value: {
...context,
...pickObj(props, textStylePick)
},
children: props.colors ? /*#__PURE__*/_jsx(RNText, {
children: /*#__PURE__*/_jsx(MaskedView, {
style: {
flex: 0
},
maskElement: /*#__PURE__*/_jsx(RNText, {
...textProps,
style: {
...textProps.style,
backgroundColor: 'transparent',
color: '#000'
}
}),
children: /*#__PURE__*/_jsx(LinearGradient, {
...pickObj(props, linearGradientPropsPick),
children: /*#__PURE__*/_jsx(RNText, {
...textProps,
style: {
...textProps.style,
opacity: 0
}
})
})
})
}) : /*#__PURE__*/_jsx(RNText, {
...textProps
})
});
};
Text.Provider = Provider;
Text.Context = TextContext;
export 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