Soundor

Text

Text, in one run with nested Text for inline styles.

Text shows text. Strings, numbers and nested <Text> inside it become one run of text, each part with its own style; numberOfLines cuts it short.

import { Text, View } from '@soundor/react';

// Text is the only place strings go. Nested <Text> continues the same run
// with its own style; numberOfLines cuts it short.
export default function Typography() {
  return (
    <View style={{ width: 300, gap: 10 }}>
      <Text style={{ fontSize: 22, fontWeight: 'bold', color: '#e6e7ea' }}>
        Warm Tape
      </Text>
      <Text style={{ fontSize: 14, color: '#8b8f98' }}>
        Saturation <Text style={{ color: '#f2b13a' }}>+3 dB</Text>, wow and
        flutter <Text style={{ fontStyle: 'italic' }}>subtle</Text>.
      </Text>
      <Text
        numberOfLines={2}
        style={{ fontSize: 14, lineHeight: 20, color: '#e6e7ea' }}
      >
        A long description is cut after two lines: the rest of this sentence
        keeps going, well past what the box has room for, and never shows.
      </Text>
    </View>
  );
}
text.tsxSource
  • Strings go in Text. A string anywhere else is an error, as in React Native: there is no text outside a text node.
  • Styles: fontSize, fontWeight, fontStyle, fontFamily, lineHeight, letterSpacing, textAlign and color, besides a view's layout and paint (Style). A nested <Text> inherits its parent's and overrides some.
  • To assistive technology a Text is read as its text, nested ones included, once. Accessibility props of a nested <Text> have no effect.

Fonts

fontFamily names one family. Bring your own by bundling the font files (TrueType .ttf or OpenType .otf) and registering each as a face of a family with registerFont from soundor:ui, before rendering:

import { registerFont } from 'soundor:ui';
import { Text } from '@soundor/react';

import interRegular from './fonts/Inter-Regular.ttf';
import interBold from './fonts/Inter-Bold.ttf';
import interItalic from './fonts/Inter-Italic.ttf';

registerFont('Inter', interRegular);
registerFont('Inter', interBold, { weight: 'bold' });
registerFont('Inter', interItalic, { style: 'italic' });

export const Title = () => (
  <Text style={{ fontFamily: 'Inter', fontWeight: 'bold' }}>Gain</Text>
);
  • As CSS's @font-face: text in a registered family is set in its registered faces, never in an installed font of the same name: the one closest to its fontWeight and fontStyle; bold and italic are synthesized when no face is. Family names match regardless of case.
  • Missing characters: a character the faces lack is drawn in a system font that has it, one character at a time. A font with Latin glyphs only shows Cyrillic or Greek text in that other font, which differs between platforms: register files that cover the scripts your UI shows.
  • The descriptors say what the file is: weight (1 to 1000, 'normal' or 'bold'; 400 by default) and style ('normal' or 'italic').
  • When: registering in the module that renders, before render(), lays text out in the font from the first frame. Text shown before is laid out again; a canvas draws in it from its next fillText().
  • The promise registerFont returns resolves once the font is ready (at once in the VST3 runtime, after the browser loaded it in the web runtime) and rejects if the file is not a font. Invalid arguments throw a TypeError.
  • Unregistered, fontFamily is a font installed on the system, which differs from one machine to the next; register the fonts a design depends on. Font files are part of the plugin binary, so check that their licence allows embedding them.

Props

Prop

Type

Text also takes the event props and the accessibility props.

On this page