Something went wrong. Try again.
Mirror — see github.com/blacksky-algorithms/blacksky.community
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109import {type FontVariant, type TextStyle} from 'react-native'
import {IS_ANDROID, IS_WEB} from '#/env'import {type Device, device} from '#/storage'
const WEB_FONT_FAMILIES = `system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji"`
const factor = 0.0625 // 1 - (15/16)const fontScaleMultipliers: Record<Device['fontScale'], number> = { '-2': 1 - factor * 1, // unused '-1': 1 - factor * 1, '0': 1, // default '1': 1 + factor * 1, '2': 1 + factor * 1, // unused}
export function computeFontScaleMultiplier(scale: Device['fontScale']) { return fontScaleMultipliers[scale]}
export function getFontScale() { return device.get(['fontScale']) ?? '0'}
export function setFontScale(fontScale: Device['fontScale']) { device.set(['fontScale'], fontScale)}
export function getFontFamily() { return device.get(['fontFamily']) || 'theme'}
export function setFontFamily(fontFamily: Device['fontFamily']) { device.set(['fontFamily'], fontFamily)}
/* * Unused fonts are commented out, but the files are there if we need them. */export function applyFonts(style: TextStyle, fontFamily: 'system' | 'theme') { if (fontFamily === 'theme') { if (IS_ANDROID) { style.fontFamily = { 400: 'Rubik-Regular', 500: 'Rubik-Regular', 600: 'Rubik-SemiBold', 700: 'Rubik-SemiBold', 800: 'Rubik-ExtraBold', 900: 'Rubik-ExtraBold', }[String(style.fontWeight || '400')] || 'Rubik-Regular'
if (style.fontStyle === 'italic') { if (style.fontFamily === 'Rubik-Regular') { style.fontFamily = 'Rubik-Italic' } else { style.fontFamily += 'Italic' } }
/* * These are not supported on Android and actually break the styling. */ delete style.fontWeight delete style.fontStyle } else { style.fontFamily = 'RubikVariable'
if (style.fontStyle === 'italic') { style.fontFamily += 'Italic' } }
if (IS_WEB) { // fallback families only supported on web style.fontFamily += `, ${WEB_FONT_FAMILIES}` }
/** * Disable contextual alternates and emoji overrides in Rubik * {@link https://developer.mozilla.org/en-US/docs/Web/CSS/font-variant} */ if (IS_WEB) { style.fontVariant = (style.fontVariant || []).concat( 'no-contextual', 'unicode' as FontVariant, // web supports 'unicode' as a valid value for fontVariant ) } else { style.fontVariant = (style.fontVariant || []).concat('no-contextual') } } else { // fallback families only supported on web if (IS_WEB) { style.fontFamily = style.fontFamily || WEB_FONT_FAMILIES }
/** * Overridden to previous spacing for the `system` font option. * https://github.com/bluesky-social/social-app/commit/2419096e2409008b7d71fd6b8f8d0dd5b016e267 */ style.letterSpacing = 0.25 }}
/** * Here only for bundling purposes, not actually used. */export {DO_NOT_USE} from '#/alf/util/unusedUseFonts'