Bluesky app fork with some witchin' additions 馃挮
at main 2.9 kB view raw
1import {type TextStyle} from 'react-native' 2 3import {isAndroid, isWeb} from '#/platform/detection' 4import {type Device, device} from '#/storage' 5 6const WEB_FONT_FAMILIES = `system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji"` 7 8const factor = 0.0625 // 1 - (15/16) 9const fontScaleMultipliers: Record<Device['fontScale'], number> = { 10 '-2': 1 - factor * 1, // unused 11 '-1': 1 - factor * 1, 12 '0': 1, // default 13 '1': 1 + factor * 1, 14 '2': 1 + factor * 1, // unused 15} 16 17export function computeFontScaleMultiplier(scale: Device['fontScale']) { 18 return fontScaleMultipliers[scale] 19} 20 21export function getFontScale() { 22 return device.get(['fontScale']) ?? '0' 23} 24 25export function setFontScale(fontScale: Device['fontScale']) { 26 device.set(['fontScale'], fontScale) 27} 28 29export function getFontFamily() { 30 return device.get(['fontFamily']) || 'theme' 31} 32 33export function setFontFamily(fontFamily: Device['fontFamily']) { 34 device.set(['fontFamily'], fontFamily) 35} 36 37/* 38 * Unused fonts are commented out, but the files are there if we need them. 39 */ 40export function applyFonts(style: TextStyle, fontFamily: 'system' | 'theme') { 41 if (fontFamily === 'theme') { 42 if (isAndroid) { 43 style.fontFamily = 44 { 45 400: 'Inter-Regular', 46 500: 'Inter-Medium', 47 600: 'Inter-SemiBold', 48 700: 'Inter-Bold', 49 800: 'Inter-Bold', 50 900: 'Inter-Bold', 51 }[String(style.fontWeight || '400')] || 'Inter-Regular' 52 53 if (style.fontStyle === 'italic') { 54 if (style.fontFamily === 'Inter-Regular') { 55 style.fontFamily = 'Inter-Italic' 56 } else { 57 style.fontFamily += 'Italic' 58 } 59 } 60 61 /* 62 * These are not supported on Android and actually break the styling. 63 */ 64 delete style.fontWeight 65 delete style.fontStyle 66 } else { 67 style.fontFamily = 'InterVariable' 68 69 if (style.fontStyle === 'italic') { 70 style.fontFamily += 'Italic' 71 } 72 } 73 74 if (isWeb) { 75 // fallback families only supported on web 76 style.fontFamily += `, ${WEB_FONT_FAMILIES}` 77 } 78 79 /** 80 * Disable contextual alternates in Inter 81 * {@link https://developer.mozilla.org/en-US/docs/Web/CSS/font-variant} 82 */ 83 style.fontVariant = (style.fontVariant || []).concat('no-contextual') 84 } else { 85 // fallback families only supported on web 86 if (isWeb) { 87 style.fontFamily = style.fontFamily || WEB_FONT_FAMILIES 88 } 89 90 /** 91 * Overridden to previous spacing for the `system` font option. 92 * https://github.com/bluesky-social/social-app/commit/2419096e2409008b7d71fd6b8f8d0dd5b016e267 93 */ 94 style.letterSpacing = 0.25 95 } 96} 97 98/** 99 * Here only for bundling purposes, not actually used. 100 */ 101export {DO_NOT_USE} from '#/alf/util/unusedUseFonts'