UI content elements — text, images, icons and video

The leaf elements that show something: UIText for text, UIImage for a photo, a picture or an icon, UIVideo for a video; what they show lives on the element (.text, .src, .player), never in a style. Typed text is UIInput (interactive.md); play and pause are the VideoPlayer's (media.md).

  • show a label or a paragraph and change it when a value changes
  • make text bigger, bold, colored or centered
  • make one word of a sentence bold or colored, or put a tappable link inside a sentence
  • cut a long description after a few lines with "…"
  • keep a label on one line, or balance a two-line headline
  • show a photo from a URL or from the project, with rounded corners
  • load a screen's pictures before showing it, so they do not pop in
  • show a small picture at once and the full photo when it arrives (preview)
  • show something else when a picture fails to load, or read a picture's size (onLoad / onError)
  • show an icon in a button and color it (assetIcon)
  • play the frames of a sprite sheet inside the UI
  • play a video inside a screen
  • show a video full screen

Platforms: iOS, Android, desktop, the web and the web player, with no guard to check; a video shows on desktop only on Windows and macOS, a Scene2D image source is not on the web or in the web player, and headless tests (lecodes render / lecodes test) draw neither (video, image sources).

At a glance

TypeScript
const photo = asset('./photo.jpg')    // a project file; a "https://…" URL string works the same way

const caption = UIText("Loading…").style({ color: "white", fontSize: 16 })

const screen = UIScreen(
  UIImage(photo).style({ width: "100%", height: 220, borderRadius: 16, objectFit: "cover" }),
  caption,
).style({ bgColor: "black", p: 16, pt: "safe-top", gap: 12 })

screen.open()
caption.text = "Sunset over the harbor"     // re-renders immediately

Show text: UIText

A label, a title or a paragraph is a UIText: pass the string, or a function that reads signals so the text follows a value.

TypeScript
UIText(text: string | (() => string)): UIText   // a function = reactive text (signals)

label.text = "Updated"      // get / set the displayed string

A counter whose label follows the value:

TypeScript
const count = signal(0)

UIScreen(
  UIText(() => `Taps: ${count.value}`).style({ fontSize: 24, color: "white" }),   // re-renders on every change
  UIButton(UIText("Add one").style({ color: "black" }))
    .style({ bgColor: "white", px: 16, py: 8, borderRadius: 8 })
    .onClick(() => { count.value++ }),
).style({ bgColor: "black", p: 16, pt: "safe-top", gap: 12, alignItems: "flex-start" }).open()
Note

text with no color of its own takes the theme's text color, and is white when the app sets no theme (theme.md). On a light background, set theme({ text: "#131A17" }) once, or a color on the text.

Note

layouts are always left to right. Arabic and Hebrew text is shaped and ordered within a line on iOS, Android and the web; desktop draws it unshaped, left to right (Not available).

Font, size, weight and color: text styles

The look of a text — size, weight, color, alignment, font — is set with .style() on the UIText, on top of the common element styles:

TypeScript
textAlign:      "start" | "center" | "end" | "left" | "right"   // default "start"
fontFamily:     string            // system: "serif", "sans-serif", "monospaced"; custom via font() (see fonts.md)
fontSize:       UIValue           // logical px, default 14
lineHeight:     UIValue | "normal"             // default "normal" = 1.2 × fontSize
fontWeight:     number | "normal" | "bold"     // 400, 700, …
fontStyle:      "normal" | "italic"
color:          Color             // unset = the theme's `text` (white without a theme)
textDecoration: "underline" | "line-through" | "none"
letterSpacing:  UIValue
lineClamp:      number            // cap at N lines; 0 / omitted = unbounded
textOverflow:   "ellipsis" | "clip"            // default ellipsis
textWrap:       "wrap" | "nowrap" | "balance" | "pretty"   // default wrap
TypeScript
UIScreen(
  UIText("Weekly report").style({ fontSize: 28, fontWeight: "bold", color: "white" }),
  UIText("Updated 5 minutes ago").style({ fontSize: 13, fontStyle: "italic", color: "#9AA0A6" }),
  UIText("Sales grew in every region: the north led with 18%, the south followed with 11%.")
    .style({ fontSize: 16, lineHeight: "1.5em", textAlign: "center", color: "white" }),   // 24 px lines
  UIText("SKU-10442").style({ fontFamily: "monospaced", letterSpacing: 1, color: "#15A34A" }),
  UIText("Read more").style({ textDecoration: "underline", color: "#5B8CFF" }),
).style({ bgColor: "black", p: 16, pt: "safe-top", gap: 8 }).open()
Note

lineHeight: 1.5 means 1.5 px — a bare number is px everywhere. A multiplier is "1.5em" or "150%" (resolved against this element's own fontSize).

UIText also takes the drawable styles — background, border, radius — so a text chip is one element: UIText("New").style({ px: 8, py: 2, bgColor: "#15A34A", borderRadius: 8, color: "white" }). Custom fonts come from the font() macro — see fonts.md.

Cut long text after N lines: lineClamp

To show a long description in a few lines ending with "…", set lineClamp: the text stops at N lines, and the element is measured to that height — the layout around it reflows around the clamped box, not around the full string.

TypeScript
const summary = "A walk through the narrow streets before the shops open: the bakeries are already busy, " +
  "the trams are nearly empty and the light on the river changes every few minutes. Bring a jacket."

UIScreen(
  UIColumn(
    UIText("Morning in the old town").style({ fontSize: 18, fontWeight: 700, color: "white" }),
    UIText(summary).style({ fontSize: 14, color: "#C8CCD0", lineClamp: 3 }),   // 3 lines, then "…"
    UIText("Read more").style({ fontSize: 14, color: "#5B8CFF" }),
  ).style({ bgColor: "#1E2126", borderRadius: 12, p: 12, gap: 6 }),
).style({ bgColor: "black", p: 16, pt: "safe-top" }).open()

textOverflow: "clip" cuts the last line instead of ending it with "…". textOverflow only takes effect together with lineClamp (or textWrap: "nowrap") — with no clamp the box is sized to the whole string, so nothing overflows. "clip" is approximate on the web: it cuts on the line-height box rather than on the glyph, so a descender on the last line may be shaved differently than on iOS. "ellipsis" is exact on both.

Keep text on one line or balance a headline: textWrap

textWrap says how a paragraph breaks into lines — one line with "…" for a label in a narrow cell, even lines for a headline. A \n in the text is a hard break in every mode; the modes decide the soft breaks (at spaces):

TypeScript
UIScreen(
  UIText("Fresh bread every morning, delivered before eight")
    .style({ fontSize: 26, fontWeight: 700, color: "white", textWrap: "balance" }),   // lines of even length
  UIRow(
    UIText("Free delivery on every order this week, no minimum")
      .style({ color: "white", textWrap: "nowrap", flexShrink: 1 }),               // one line, ends with "…"
    UIText("New").style({ px: 8, py: 2, bgColor: "#15A34A", borderRadius: 8, color: "white" }),
  ).style({ gap: 8, alignItems: "center" }),
).style({ bgColor: "black", p: 16, pt: "safe-top", gap: 12 }).open()
  • "wrap" (the default) is the greedy wrap: each line takes as many words as fit.
  • "nowrap" never breaks at a space. The element is measured to the whole line, so in a row it pushes its siblings or overflows its parent, as CSS white-space: nowrap does; a line wider than the box the element finally gets is ended with "…" (textOverflow: "clip" lets it run past the box instead). The usual shapes: a label in a fixed-width cell (an ellipsis instead of a second line), a chip whose width is its text, a ticker inside a horizontal scroll.
  • "balance" wraps at the narrowest width that keeps the greedy line count, so a two-line headline gets two half-width lines instead of a full line and a word. It applies to paragraphs of 2 to 10 lines; longer ones wrap greedily.
  • "pretty" moves the last word of the line before down when the last line would be a single word and the pair fits the width.

balance and pretty wrap greedily on a paragraph a lineClamp cuts, so the ellipsis lands on a full line.

A UIText inside a UIText is a run: it is drawn inline, as a part of the outer text's paragraph, with its own style and its own onClick — a bold word in a sentence, a link the user taps, a price that follows a signal. A string among the parts is a run in the paragraph's style, a UIImage an icon in the line (below).

TypeScript
UIText(...parts: (UITextPart | UITextPart[])[]): UIText     // UITextPart = string | UIText | UIImage | null | undefined | false
UIText(parts: UITextPart[] | (() => string | UITextPart[])): UIText   // a function = reactive parts

A sentence with a link, and a total whose number follows a signal:

TypeScript
const total = signal(1290)

UIScreen(
  UIText(
    "By continuing you accept the ",
    UIText("terms").style({ color: "#5B8CFF", textDecoration: "underline", $pressed: { opacity: 0.5 } })
      .onClick(() => console.log("open the terms")),
    ".",
  ).style({ fontSize: 15, lineHeight: "1.4em", color: "white" }),
  UIText("Total: ", UIText(() => `${total.value} ₽`).style({ fontWeight: 700 }))   // a reactive run
    .style({ fontSize: 18, color: "white" }),
  UIButton("Add 10").style({ bgColor: "white", color: "black", px: 16, py: 8, borderRadius: 8 })
    .onClick(() => { total.value += 10 }),
).style({ bgColor: "black", p: 16, pt: "safe-top", gap: 12, alignItems: "flex-start" }).open()
  • Runs nest. A run inside a run takes both styles: UIText("Hello ", UIText("big ", UIText("red").style({ color: "#FF3B30" })).style({ fontWeight: 700 })). Only the innermost texts hold strings; a text with runs has no string of its own.
  • What a run styles. A run takes the paragraph's text style and changes what it sets itself: color, fontSize, fontWeight, fontStyle, fontFamily, letterSpacing, textDecoration and backgroundColor (a highlight behind its letters). The paragraph's own props — lineHeight, textAlign, lineClamp, textOverflow, textWrap — and every box prop (padding, border, size) belong to the outer text; set on a run, they are ignored.
  • One line, one baseline. Every line is the paragraph's lineHeight tall and every run on it sits on one baseline; a run with a larger fontSize shares it and may stick out of the line, as a large font does. Lines wrap at spaces across runs (a word may change style in the middle), a \n in any run breaks the line, lineClamp counts the paragraph's lines and the "…" is drawn in the font of the run it cuts. An underline or a line-through is the run's own, in its color.
  • Taps. A run with onClick is a touch target: a tap on its letters goes to it (to the innermost run with a listener), a tap elsewhere in the paragraph to the paragraph. Its $pressed / $hovered blocks work as on a button. A run has no box of its own, so no onLayout.
  • The paragraph's text. el.text of the outer text reads the strings of its runs in order — "By continuing you accept the terms." above, the same string a test flow's text target and expect match. Assigning el.text = "…" replaces the runs with that one string.
  • Reactive parts. UIText(() => [...]) re-renders the parts when a signal it read changes: a string at the same place is updated in place, a UIText run still in the list stays mounted. The function may return a string instead — the text is then a plain string again.
  • Strings among a box's children are texts too. UIButton("Pay") and UIColumn("Title", UIText("Subtitle")) make each string a UIText with no style of its own (it takes the text props of the containers above it). In a text a string is a run; in a box it is a block, so two strings in a column are two lines. Pieces that flow in one line are one text: UIButton(UIText("Buy ", UIText("now").style({ fontWeight: 700 }))).

Icons in a line

A UIImage among the parts is an icon in the line: it flows with the words, wraps with them and takes a tap like a run.

TypeScript
UIScreen(
  UIText("Pay ", UIImage(assetIcon("lucide:credit-card")).style({ width: 16, height: 16, tintColor: "white" }), " by card")
    .style({ fontSize: 16, color: "white" }),
  UIText("Tap ", UIImage(assetIcon("lucide:info")).style({ tintColor: "#5B8CFF" })   // no size: a 1em square
    .onClick(() => console.log("about")), " for details")
    .style({ fontSize: 24, color: "white" }),
).style({ bgColor: "black", p: 16, pt: "safe-top", gap: 12, alignItems: "flex-start" }).open()
  • Size. The icon's width and height in px. With one of them, the other follows the picture's proportions (a square until the picture has loaded); with neither, it is a square as tall as the paragraph's fontSize (1em). A percent or "auto" counts as not set.
  • Place in the line. The icon is centred on the middle of the paragraph's lowercase letters (CSS vertical-align: middle). A tall icon shares the line's baseline as a run with a larger font does and sticks out of the line box; the line stays the paragraph's lineHeight tall. It advances exactly its width (letterSpacing does not apply) and never breaks — a space on either side is where a line may break.
  • Style. Its own tintColor, opacity and borderRadius (an avatar in a line); the picture covers its box (objectFit: "cover"). Padding, margin and border are ignored, as on a text run; the text color does not tint it — set tintColor. The source is a picture (a URL, a project file, an SVG); a Canvas or a Scene2D source is not drawn in a line.
  • Taps and text. onClick on the icon makes it a touch target, like a run. It adds no characters: el.text of the paragraph is "Pay by card", and a test flow reaches the icon by its name, not by text.

Only strings, numbers (read as their string), UIText and UIImage are parts: a box inside a text is reported in the log and skipped.

Note

runs — icons in a line too — draw on every host — iOS, Android, desktop, the web player, headless tests and the web (Web Lite) — on one model: the paragraph's lineHeight is the line box, every run of a line sits on one baseline, a larger run overflows the line visibly, words wrap across run boundaries, and the ellipsis of a clamped paragraph takes the style of the first hidden run. On the web the browser breaks the lines and styles the ellipsis as the paragraph, and a larger run grows its line; the other hosts break lines themselves.

Show an image: UIImage

A photo, a picture or an icon is a UIImage: give it a URL or a project file (or a downloaded or picked file, an SVG, a canvas, a 2D scene), a size, and swap the picture later through .src.

TypeScript
UIImage(src: ImageSource): UIImage

img.src            // get the (resolved) source / set a new one — the picture changes in place
img.onClick(fn)    // a tap on the image (its `$pressed` / `$hovered` scope at it, as a button's)
img.preview(src)   // a picture shown in the box until the one of `src` is there
img.onLoad(fn)     // the picture is there: ({ width, height }) — its own pixels
img.onError(fn)    // the picture will not be there: (error)

A photo from a URL with rounded corners, and a button that shows the next one:

TypeScript
const photos = ["https://example.com/photos/harbor.jpg", "https://example.com/photos/market.jpg"]
let shown = 0

const photo = UIImage(photos[0]).style({ width: "100%", height: 240, borderRadius: 16, objectFit: "cover" })

UIScreen(
  photo,
  UIButton(UIText("Next photo").style({ color: "black" }))
    .style({ bgColor: "white", px: 16, py: 8, borderRadius: 8 })
    .onClick(() => { shown = (shown + 1) % photos.length; photo.src = photos[shown] }),   // swaps in place
).style({ bgColor: "black", p: 16, pt: "safe-top", gap: 12, alignItems: "flex-start" }).open()

Where the picture comes from: image sources

TypeScript
// ImageSource:
//   string          — a remote URL, or a project file: asset('./photo.jpg') or the path itself
//   FetchResponse   — a downloaded body used directly as pixels
//   File            — from openFilePicker() (files-share.md) or a CameraView photo
//   SvgSource       — wrapped raw SVG XML; assetIcon() and asset('./icon.svg') return one
//   Canvas          — a 2D Canvas, baked to a texture on assign; canvas.update() refreshes the image
//   Scene2D         — a live 2D scene, drawn into the box every frame (a minimap); no intrinsic
//                     size — give the element a width and height

A photo the user picks from the library is a File: UIImage(file) — the complete form is in Files & share. A Scene2D source needs no open() — see Scene2D — Inside UI.

Note

a project file by its path as a string — UIImage("images/photo.png"), "./photo.png" from the file — is the bundled asset, the same as asset('./images/photo.png'); such a path that names no file fails the compile (file not found). Plain https://… strings are remote URLs.

Note

a Scene2D source draws on iOS, Android and desktop; not on the web or in the web player, and headless tests leave its box empty.

Fill the box, round the corners, tint: image styles

How the picture fills its box, its corners and an icon's color are styles of the UIImage:

TypeScript
objectFit:    "cover" | "contain" | "fill"   // how the source maps into the box; default "cover"
tintColor:    Color                          // SVG sources only (any color or var())
borderRadius: number                         // px (a number only on UIImage)
Note

tintColor applies only to SVG sources, and it replaces all fill and stroke colors in the SVG — it's for monochrome icons, not multicolored artwork. (The desktop host tints a raster image too, into a flat silhouette; the phones and headless renders don't — don't rely on it.)

Load a picture before it is shown: preloadImage

A picture from a URL arrives after its element is on screen: the box is empty first and fills in. preloadImage loads the picture ahead, so the element that shows it later draws it at once — the pictures of a first screen behind the launch screen, the next slide of a story, the photo of a page about to be pushed.

TypeScript
preloadImage(url: string, size?: { width?: number, height?: number }): Promise<void>
TypeScript
const cover = "https://example.com/photos/harbor.jpg"

const openPhoto = async () => {
  await preloadImage(cover, { width: 360, height: 240 }).catch(() => {})   // a picture that fails is an empty box, as always
  Router.push(UIScreen(
    UIImage(cover).style({ width: 360, height: 240, borderRadius: 16, objectFit: "cover" }),
  ).style({ bgColor: "black", p: 16, pt: "safe-top" }))
}

UIScreen(
  UIButton(UIText("Open the photo")).onClick(openPhoto),
).style({ p: 16, pt: "safe-top" }).open()

It is the same load a UIImage of that address makes: one request, whichever of the two asks first, and the picture stays in the app's image cache for every element that shows it afterwards. Several pictures at once: await Promise.allSettled(urls.map((url) => preloadImage(url, size))).

size is the box the picture will be shown in, in logical px. With it the picture is also prepared at that size, and the element shows it in its first frame. Without it only the file is brought: the element still has to decode it, which shows as an empty box for a moment on a large photo — pass the size whenever it is known.

The promise rejects when the picture cannot be loaded (no network, a 404, a file that is not an image); the message names the address. A source that is not a URL — a project file, an SVG, a picked file — is in the app already and resolves at once.

Note

preparing the picture at the box's size is iOS and Android. On desktop, the web and the web player size is not needed (the picture is kept whole); in headless tests and on a host older than this function the promise resolves at once, without loading anything.

Show a small picture until the photo is there: preview

A list shows a small copy of each photo; the page behind a row shows the full one, which takes a moment to arrive. preview puts the small copy in the box meanwhile — it is on the device already, so it is there in the first frame — and the photo takes its place the moment it can be drawn.

TypeScript
img.preview(src: string | FetchResponse | File | null): UIImage   // null takes it away
TypeScript
const photo = { src: "https://example.com/photos/harbor.jpg", thumb: "https://example.com/photos/harbor-256.jpg" }

UIScreen(
  UIImage(photo.src).preview(photo.thumb)
    .style({ width: "100%", aspectRatio: 1.5, borderRadius: 16, objectFit: "cover", bgColor: "#e6e6e6" }),
).style({ p: 16, pt: "safe-top" }).open()

The preview is drawn as the photo will be — the same objectFit and corners — and it never sizes the element: give the image a width and a height, or an aspectRatio. It stays in the box when the photo fails to load. A preview that cannot be loaded itself is no preview: the box shows its bgColor, and nothing is reported. It is kept for the sources set later, so when the photo changes set the two together: img.preview(next.thumb); img.src = next.src. With .cache(mode) the preview is kept on the device in the same mode.

Know that a picture loaded or failed: onLoad, onError

TypeScript
img.onLoad((size: { width: number, height: number }) => void): UIImage   // its own pixels (an SVG: its document's size)
img.onError((error: Error) => void): UIImage                             // the message names the address

One of the two is called once for every source the image is given — again after img.src = …. A picture that is in the app's image cache already is reported too, right after the element is shown. A photo whose proportions are not known ahead takes them from onLoad; a picture that fails is replaced by what stands for it:

TypeScript
const url = "https://example.com/photos/harbor.jpg"
const ratio = signal(1.5), failed = signal(false)

UIScreen(
  UIImage(url)
    .style({ width: "100%", aspectRatio: () => ratio.value, display: () => failed.value ? "none" : "flex" })
    .onLoad(({ width, height }) => { ratio.value = width / height })
    .onError(() => { failed.value = true }),
  UIText("The photo could not be loaded").style({ display: () => failed.value ? "flex" : "none" }),
).style({ p: 16, pt: "safe-top", gap: 12 }).open()

A picture is loaded when its element is first laid out or drawn, so an image that was never on screen reports nothing yet. A Canvas and a Scene2D source are live — there is nothing to load, and neither function is called. Without onError a picture that fails is an empty box with its bgColor, as always.

Note

on iOS and Android onLoad is called when the file is read as a picture and its size is known — before its pixels are decoded for the box. On desktop and the web it is called once the picture is decoded. A photo from a camera reports its size as it is shown, turned upright.

Add an icon to a button or a list row: assetIcon("pack:name")

To add an icon to a button, a tab or a list row, use the assetIcon() compile macro rather than hand-written SVG: it resolves one icon from the icon registry at build time and inlines it as an image source — an SvgSource, the one type asset('./x.svg') and SvgSource(xml) give too, so a component that takes an icon is typed (icon: SvgSource) — and it renders offline and identically on every host, with no network at render time.

TypeScript
UIScreen(
  UIButton(
    UIImage(assetIcon("lucide:bell")).style({ width: 20, height: 20, tintColor: "white" }),
    UIText("Notifications").style({ color: "white" }),
  ).style({ bgColor: "#15A34A", px: 16, py: 10, gap: 8, borderRadius: 10 }),
  UIImage(assetIcon("lucide:check", { color: "#15A34A" })).style({ width: 24, height: 24 }),   // baked green
).style({ bgColor: "black", p: 16, pt: "safe-top", gap: 12, alignItems: "flex-start" }).open()

The "pack:name" id must be a string literal (an unknown id is a compile error; browse packs at https://icon-registry.jt3.ru). Recolor with the { color } option — a color literal is baked into the SVG at compile time, a token/expression (a theme var() too — it follows the live theme) is applied as the source's own tint — or with the tintColor style prop, which wins over the source's tint.

Show one frame of a sprite sheet: setSourceRect

TypeScript
img.setSourceRect(x: number, y: number, w: number, h: number): this   // texture pixels

To show one frame of an atlas or a sprite sheet, crop the source to a sub-rectangle. The rect's w/h become the element's intrinsic size (one frame, not the whole atlas), and the cropped frame always fills the box, overriding objectFit. Chainable and safe to call before the element is on screen. A sprite animation swaps the rect per frame:

TypeScript
// coins.png: 8 frames of 128×128 side by side (1024×128)
const coin = UIImage(asset('./coins.png')).style({ width: 64, height: 64 }).setSourceRect(0, 0, 128, 128)

let frame = 0
const timer = setInterval(() => { frame = (frame + 1) % 8; coin.setSourceRect(frame * 128, 0, 128, 128) }, 100)

UIScreen(coin)
  .style({ bgColor: "black", p: 16, pt: "safe-top" })
  .onClose(() => clearInterval(timer))
  .open()

Play a video in a screen: UIVideo

A video played inside a screen is a UIVideo showing a VideoPlayer: the element is only the picture, playback lives on the player — create the player first and control it directly.

TypeScript
UIVideo(player: VideoPlayer): UIVideo

video.player       // read-only — the VideoPlayer passed at construction
TypeScript
const movie = new VideoPlayer(asset('./intro.mp4'))   // or a "https://…" URL
movie.loop = true

const video = UIVideo(movie).style({ width: "100%", height: 220, borderRadius: 12, objectFit: "cover" })

UIScreen(
  video,
  UIButton(UIText("Play / pause").style({ color: "black" }))
    .style({ bgColor: "white", px: 16, py: 8, borderRadius: 8 })
    .onClick(() => { movie.playing = !movie.playing }),
).style({ bgColor: "black", p: 16, pt: "safe-top", gap: 12, alignItems: "flex-start" })
  .onOpen(() => movie.play())
  .onClose(() => movie.stop())     // stop it when the screen closes
  .open()

objectFit: "cover" | "contain" | "fill" (default "cover") maps the video into the box, and UIVideo takes the drawable styles (border*, bgColor, radius) for framing. The player is released by itself once nothing references it and it is not playing.

Note

the video shows on iOS, Android, the web, the web player and desktop on Windows and macOS. Linux desktop keeps a placeholder box, and headless tests lay out an empty box — nothing plays there.

Play a video full screen: a screen holding it

A UIVideo is a part of a screen, never a destination — there is no video.open(). To play a video full screen, push a screen that holds a UIVideo of the SAME player at flex: 1: playback lives on the player, so it plays on as the screen comes in, and back — Android's back button, the iOS swipe, Router.pop() — returns to the screen under it, the player still going. The controls over it are that screen's widgets — a close button, a HUD:

TypeScript
const movie = new VideoPlayer("https://example.com/videos/trailer.mp4")
const video = UIVideo(movie).style({ width: "100%", height: 200, objectFit: "contain" })

// full screen: a screen of its own around a second UIVideo of the same player
const fullScreen = () => UIScreen(
  UIVideo(movie).style({ flex: 1, objectFit: "contain" }),
).style({ bgColor: "black" }).widgets(
  UIWidget(UIButton(UIText("Close").style({ color: "white" })).onClick(() => Router.pop()))
    .style({ top: "safe-top", right: 16, bgColor: "#00000080", px: 12, py: 6, borderRadius: 8 }),
)

const details = UIScreen(
  video,
  UIButton(UIText("Full screen").style({ color: "black" }))
    .style({ bgColor: "white", px: 16, py: 8, borderRadius: 8 })
    .onClick(() => Router.push(fullScreen(), { transition: "fade" })),   // the same player, on a screen of its own
).style({ bgColor: "black", p: 16, pt: "safe-top", gap: 12, alignItems: "flex-start" })

Router.init(details)
movie.play()

The screen it covers gets its onClose — a screen that stops its player in onClose (the example above) stops the full-screen video too; stop it where the user leaves instead (the full-screen screen's own onClose fires on the way back as well).

Note

a player shows in every UIVideo made for it. On iOS and desktop each of them draws the picture; on Android, the web and the web player a player has one picture at a time, and it is in the newest of its videos that is on screen — the full-screen one while it is pushed, the box again after the pop.

Pitfalls

TypeScript
const img = UIImage("")                  // ✗ an empty source as a placeholder, filled in later
const img = UIImage(firstUrl)            // ✓ the source at construction… img.src = nextUrl swaps it

UIBox().style({ width: 64, height: 64, bgImage: avatarUrl })   // ✗ a picture as an empty box's background
UIImage(avatarUrl).style({ width: 64, height: 64 })            // ✓ content is a UIImage (fit, tint, crop)

UIImage(photo).preview(thumb)                                   // ✗ no size: a preview never sizes the element
UIImage(photo).preview(thumb).style({ width: "100%", aspectRatio: 1.5 })   // ✓

await preloadImage(url)                  // ✗ on a phone the element still decodes a large photo: an empty box for a moment
await preloadImage(url, { width: 360, height: 240 })   // ✓ the size it is shown in: there in the first frame

import photo from './photo.jpg'          // ✗ bundles, but the type check fails
const photo = asset('./photo.jpg')       // ✓ or the path as a string: UIImage("./photo.jpg")

See also

  • UI element model — content props vs styles, capturing refs
  • Styling — common styles, units, em resolution, bgImage behind children
  • Theme — the default text color and font of the whole app
  • Fonts — the font() macro and registerFont for custom fontFamily
  • App lifecycle — app.splash: keep the launch screen until the first screen's pictures are loaded
  • Media players — VideoPlayer control surface
  • Interactive elements — UIInput / UITextArea for editable text