UNPKG

@livelike/react-native

Version:

LiveLike React Native package

51 lines (50 loc) 1.57 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.useCustomFontStyle = useCustomFontStyle; var _react = require("react"); var _reactNative = require("react-native"); var _useFonts = require("./useFonts"); var _useFontFamily = require("./useFontFamily"); /** * @description useCustomFontStyle hook returns an evaluated styles for Text based Component * based on fontWeight and fontStyle, these tweaked style are needed because of platform (IOS & Android) * limitation for custom fonts * @returns styles */ function useCustomFontStyle(_ref) { let { style } = _ref; const { fontFamily, fontFamilyType } = (0, _useFontFamily.useFontFamily)({ style }); const { fonts } = (0, _useFonts.useFonts)(); const styles = (0, _react.useMemo)(() => { const _styles = _reactNative.StyleSheet.flatten([style, { fontFamily }]); // Android has limitation for custom fonts where if custom font is used // and fontWeight/fontStyles is set, it doesn't render the expected font // so skipping fontWeight (& fontStyle) styles for Android platform // for more context refer https://stackoverflow.com/a/55717885/4317128 const isCustomFont = !!fonts[fontFamilyType]; if (_reactNative.Platform.OS === 'android' && isCustomFont) { const { fontWeight, fontStyle, ...restStyles } = _styles; return restStyles; } return _styles; }, [fontFamily, style, fontFamilyType]); return styles; } //# sourceMappingURL=useCustomFontStyle.js.map