Expand description
day-piece-remote-image — an EXTERNAL Day Piece (DESIGN.md §15): a NATIVE image view that decodes
encoded bytes (PNG/JPEG) supplied reactively and draws them, with a placeholder rectangle
while the source is empty. This is the image primitive a Matrix client needs — avatars and inline
image messages — where the app fetches mxc:// bytes off the UI thread via the SDK and pushes
them into a signal; this piece only turns bytes into a native image.
Unlike day’s built-in image (which loads a bundled asset by name), the source here is
Signal<Option<Arc<Vec<u8>>>>: None shows the placeholder color; Some(bytes) decodes and
displays. The Arc<Vec<u8>> is shared, so pushing a large buffer from a background decode is a
refcount bump, not a copy. The piece is a growing leaf that fills its frame (constrain it with
.frame(w, h)); avatars occupy their box even before any bytes arrive.
let avatar: Signal<Option<Arc<Vec<u8>>>> = Signal::new(None);
// …app pushes decoded bytes later: avatar.set(Some(Arc::new(png_bytes)));…
remote_image(avatar).circle().placeholder_color(Color::hex(0xD0D0D0)).frame(40.0, 40.0)Structs§
- Remote
Image - A native image view whose content mirrors
source(aSignal<Option<Arc<Vec<u8>>>>). Shape it with.circle()/.rounded(r), scale it with.content_mode(_), and set the empty-state color with.placeholder_color(_). - Remote
Image Props - Full props (realize).
bytesseeds the view; all four are applied at build. Onlybyteschanges after build, viaRemoteImagePatch::SetBytes.
Enums§
- Clip
- How the piece (image AND placeholder) is clipped to its frame.
- Content
Mode - How the decoded image is scaled into the piece’s frame.
- Remote
Image Patch - The single imperative update: replace the displayed bytes (or clear to the placeholder).
Constants§
Functions§
- remote_
image remote_image(source)— a native image view that decodes and displays the bytes held insource, showing the placeholder color wheneversourceisNone.- remote_
image_ url remote_image_url(url)—remote_imagewith the fetch built in: the bytes are downloaded once through the PLATFORM HTTP stack (day-part-http— system proxies/VPN/Low-Data aware, docs/http.md) on a background completion, and pushed into the piece’s own signal via aSetter(so a late arrival after the piece is disposed is a harmless no-op). The placeholder shows until the bytes land; a failed fetch (or non-2xx status) leaves the placeholder.