UNPKG

@livelike/react-native

Version:

LiveLike React Native package

54 lines (53 loc) 1.45 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.useFontFamily = useFontFamily; var _reactNative = require("react-native"); var _useFonts = require("./useFonts"); var _react = require("react"); /** * @description useFontFamily hook returns an evaluated fontFamily based on fontWeight and fontStyle * This is useful in case of custom fonts. * @returns fontFamily and fontFamilyType */ function useFontFamily(_ref) { let { style } = _ref; const { fonts } = (0, _useFonts.useFonts)(); return (0, _react.useMemo)(() => { const fontFamilyType = getFontFamilyType(style); return { fontFamilyType, fontFamily: fonts[fontFamilyType] }; }, [style, fonts]); } function getFontFamilyType(style) { const { fontWeight, fontStyle } = _reactNative.StyleSheet.flatten(style); const isItalicFontStyle = fontStyle === 'italic'; const weightMap = { '100': 'thin', '200': 'extraLight', '300': 'light', '500': 'bold', '600': 'semiBold', bold: 'bold', '700': 'bold', '800': 'extraBold', '900': 'black' }; const weightKey = fontWeight === null || fontWeight === void 0 ? void 0 : fontWeight.toString(); const weightType = weightMap[weightKey]; if (weightType) { return isItalicFontStyle ? `${weightType}Italic` : weightType; } return isItalicFontStyle ? 'italic' : 'regular'; } //# sourceMappingURL=useFontFamily.js.map