Command palette

@yasinsensoy/native

React Native · APIs and utilities

Fonts

The Inter font family, with only the weights added to the app.

13 exports

Import

import {
  weightNumber,
  pickFontFile,
  resolveFont,
  INTER_WEIGHTS,
  INTER_ITALIC_WEIGHTS,
  interFont,
  inter,
} from "@yasinsensoy/native";

interFont

function

The Inter font family, with only the weights added to the app. Details and setup: inter.

interFont({ weights, italic, }?: InterOptions): FontFamily

Examples

// ui.config.ts: fonts: [{ family: "inter", weights: [300, 400, 600, 800] }]
<UIProvider fontFamily={interFont({ weights: [300, 400, 600, 800] })}>…</UIProvider>

weightNumber

function

Converts a weight to a 100–900 number.

weightNumber(weight: FontWeightInput | undefined): number

pickFontFile

function

Picks the file nearest to the requested weight (CSS rule: for 400 try 500 first, for 500 try 400 first; when bolder is requested try bolder first, when lighter try lighter first).

pickFontFile(files: Partial<FontFiles>, weight: number): string | undefined

resolveFont

function

Produces a style from family, weight and slant. With an object family the right file's name becomes fontFamily and fontWeight is not set (Android would pick the wrong file or fake the bold).

resolveFont(family: FontFamily | undefined, weight: FontWeightInput | undefined, italic?: boolean): FontStyle

Inter weights shipped with the library.

INTER_WEIGHTS: readonly [100, 200, 300, 400, 500, 600, 700, 800, 900]

Inter italic weights.

INTER_ITALIC_WEIGHTS: readonly [400, 500, 600, 700]

inter

constant

The library's bundled font: Inter (SIL Open Font License 1.1). Designed for screens, with weights 100–900 and Latin, Turkish, Greek and Cyrillic characters. Since the same files are used on iOS and Android, text is drawn exactly the same on both platforms (the system fonts San Francisco and Roboto differ).

It goes into the app only when requested: add fonts: ["inter"] to ui.config.ts and run npx yasinsensoy-native sync (Android assets/fonts, the iOS Fonts folder and UIAppFonts). The default weights are 400, 500, 600 and 700; for other weights see interFont.

inter: FontFamily

Examples

import { inter } from "@yasinsensoy/native/font";
<UIProvider fontFamily={inter}>…</UIProvider>

Weight name (CSS 100–900 scale).

type FontWeightName = "thin" | "extralight" | "light" | "regular" | "medium" | "semibold" | "bold" | "extrabold" | "black"

Weight: a name, a number (600) or the React Native form ("600", "bold").

type FontWeightInput = FontWeightName | number | NonNullable<TextStyle["fontWeight"]>

A file per weight (the font's PostScript name = the file name).

type FontFiles = { /** File of the regular (400) weight; required. */ regular: string; } & Partial<Record<FontWeightName, string>>

Extends: Partial<Record<FontWeightName, string>>

NameTypeDescription
regularstringFile of the regular (400) weight; required.

Font family.

  • String ("Inter"): a single name; the weight is picked with fontWeight. Works correctly only for fonts where the platform can find the weights in the family (the system font, files registered to one family on iOS).
  • Object: a separate file per weight. This is the way that gives exactly the same result on both platforms (Android cannot pick the weight from the family). A missing weight falls back to the nearest one. The library's bundled font: inter.
type FontFamily = string | (FontFiles & { italic?: Partial<FontFiles>; })

Examples

`{ regular: "Brand-Regular", bold: "Brand-Bold", italic: { regular: "Brand-Italic" } }`

FontStyle

interface

Result of resolveFont: values to add to a Text style.

NameTypeDescription
fontFamily?stringFont family name.
fontWeight?TextStyle["fontWeight"]Font weight.
fontStyle?TextStyle["fontStyle"]"italic" for italic.

InterOptions

interface

Options of interFont; must match the ui.config fonts setting.

NameTypeDefaultDescription
weights?readonly number[][400, 500, 600, 700]Weights added to the app.
italic?booleanfalseWhether italics were added (400–700).