Open History to see the last commit
1import { Platform } from "react-native";
2
3export type MobileFontId = "system" | "dm-sans";
4export type MobileMonoFontId = "system" | "meslo";
5
6export interface MobileFontFamilies {
7 readonly regular: string;
8 readonly medium: string;
9 readonly bold: string;
10}
11
12const SYSTEM_FAMILY = Platform.OS === "ios" ? "System" : "sans-serif";
13const SYSTEM_MONO_FAMILY = Platform.OS === "ios" ? "ui-monospace" : "monospace";
14
15// A system family has one name for every weight, so text picks its weight with fontWeight;
16// MesloLGS NF does too (app.config.ts maps its weights). Keep bundled names aligned with app.config.ts.
17export const MOBILE_FONT_FAMILIES: Readonly<Record<MobileFontId, MobileFontFamilies>> = {
18 system: { regular: SYSTEM_FAMILY, medium: SYSTEM_FAMILY, bold: SYSTEM_FAMILY },
19 "dm-sans": { regular: "DMSans-Regular", medium: "DMSans-Medium", bold: "DMSans-Bold" },
20};
21
22export const MOBILE_MONO_FONT_FAMILIES: Readonly<Record<MobileMonoFontId, string>> = {
23 system: SYSTEM_MONO_FAMILY,
24 meslo: "MesloLGS-NF-Regular",
25};
26
27export const DEFAULT_MOBILE_FONT_ID: MobileFontId = Platform.OS === "ios" ? "system" : "dm-sans";
28export const DEFAULT_MOBILE_MONO_FONT_ID: MobileMonoFontId = "system";
29
30export function resolveMobileFontId(value: unknown): MobileFontId {
31 return value === "system" || value === "dm-sans" ? value : DEFAULT_MOBILE_FONT_ID;
32}
33
34export function resolveMobileMonoFontId(value: unknown): MobileMonoFontId {
35 return value === "system" || value === "meslo" ? value : DEFAULT_MOBILE_MONO_FONT_ID;
36}
37
38export function resolveFontFamilyVariables(
39 fontId: MobileFontId,
40 monoFontId: MobileMonoFontId,
41): Record<string, string> {
42 const families = MOBILE_FONT_FAMILIES[fontId];
43 return {
44 "--font-sans": families.regular,
45 "--font-medium": families.medium,
46 "--font-bold": families.bold,
47 "--font-mono": MOBILE_MONO_FONT_FAMILIES[monoFontId],
48 };
49}