LavaUI docs GitHub

struct Image

Swift

struct Image

Raster image laid out as a Yoga leaf and drawn as a textured quad.

One specified axis keeps the pixel aspect: Image(logo, width: .pt(80)) on a 200×100 bitmap is an 80×40 box. Both auto is the native size; both set is the box contentMode paints into.

Image(logo, width: .pt(64), height: .pt(64))
Image(icon)  // intrinsic pixel size
Image(photo, width: .pt(120))  // height from aspect

Sources/LavaUI/Image.swift:463

Constructors

init(_ image: UIImage, width: Dimension = .auto, height: Dimension = .auto, tint: Color = Color(r: 1, g: 1, b: 1), contentMode: ImageContentMode = .stretch, onClick: (() -> Void)? = nil)

Draws an image that is already loaded.

Leave both sizes .auto for the bitmap's own size, or give one and the other follows its aspect.

Sources/LavaUI/Image.swift:487

init(path: String, width: Dimension, height: Dimension, placeholder: Color? = nil, placeholderCornerRadius: Float = 0, decodePixels: UInt32? = nil, tint: Color = Color(r: 1, g: 1, b: 1), contentMode: ImageContentMode = .stretch, onClick: (() -> Void)? = nil)

An image identified by file path, loaded on demand and drawn when ready.

Prefer this to branching on ImageStore.imageIfLoaded in a body. Writing it as if let img = …imageIfLoaded(…) { Image(img) } else { placeholder } makes the shape of the view tree depend on whether a decode has finished, so every arriving image has to invalidate body and rebuild the tree. Here the leaf is the same leaf either way; it resolves its own texture at emit, and an arriving image costs one redraw.

width/height must be definite for the decode cap to be derived from them — with .auto there is no box to size against yet, and the file decodes at native resolution. Pass decodePixels to override.

Sources/LavaUI/Image.swift:515

Properties

var contentMode: ImageContentMode

How the bitmap maps into the box.

Sources/LavaUI/Image.swift:479

var dumpDetail: String { get }

Not documented.

Sources/LavaUI/Image.swift:556

var height: Dimension

Height of the box. With the other axis .auto, the other follows the bitmap's aspect.

Sources/LavaUI/Image.swift:475

var image: UIImage?

The image to draw, or nil when the view was created from a path.

Sources/LavaUI/Image.swift:465

var onClick: (() -> Void)?

Called when the image is clicked.

Sources/LavaUI/Image.swift:481

var path: String?

Set instead of image by the path initialiser — see its doc comment.

Sources/LavaUI/Image.swift:467

var placeholder: Color?

Fill drawn while a path-based image is still loading, or nil for nothing.

Sources/LavaUI/Image.swift:469

var placeholderCornerRadius: Float

Corner radius of the placeholder fill, in points.

Sources/LavaUI/Image.swift:471

var tint: Color

Multiplied with sample RGBA (white = no tint).

Sources/LavaUI/Image.swift:477

var width: Dimension

Width of the box. With the other axis .auto, the other follows the bitmap's aspect.

Sources/LavaUI/Image.swift:473

Methods

func mountPrimitive() -> any AnyViewNode

Not documented.

Sources/LavaUI/Image.swift:565

func reconcilePrimitive(_ node: any AnyViewNode) -> any AnyViewNode

Not documented.

Sources/LavaUI/Image.swift:578