Images
<img> and background-image url() from bundle assets, the network and data URLs, laid out and clipped as Chrome does.
Write images the way you would on the web. BakeNative lays them out and clips them like Chrome
(the core computes every box and draw rectangle), and the host decodes and draws them.
Every target draws images: the web, Windows, iOS, macOS and Android, from bundle assets,
data: URLs and the network. Network (http(s)) images load through the platform's fetch
transport (WinHTTP, URLSession, Android's HttpURLConnection) into the core's shared cache.
On Android a cleartext http:// image follows the app's Network Security Config: HTTPS only
by default (Network images on Android).
In a new screen, use the built-in Image from @bake-native/react or @bake-native/octane.
Pass an imported image, or a { uri } object for a remote image, as source. Set resizeMode
to cover, contain, stretch, or center. Image draws through the same host image view as
<img>.
import { Image } from '@bake-native/react';
import cover from './cover.png';
<Image source={cover} resizeMode="contain" alt="Album cover" style={{ width: 96, height: 96 }} />Use <img> when you reuse web markup, or when you need the width, height, or loading
attributes, or onLoad and onError. Caching and decoding work the same for both. See
Use built-in views first.
import logo from './logo.svg';
export function Card(props) @{
<article class="card">
<img class="cover" src="./photos/hero.jpg" width="320" height="180" alt="Hero" />
<img src={logo} alt="Logo" />
<img src={props.avatarUrl} width="48" height="48" loading="lazy"
onLoad={() => console.log('avatar shown')} onError={() => console.log('no avatar')} />
</article>
<style>
.cover { width: 100%; height: auto; object-fit: cover; border-radius: 12px; }
.card { background: #f4f4f6 url(./pattern.png) top left / 24px repeat; }
</style>
}Sources
| Source | What happens |
|---|---|
./relative/path.png in <img src>, CSS url() or an import | bake build copies it to assets/<name>.<hash>.<ext>, lists its natural size in manifest.json, and points the bundle at it. The baked layout reserves the image’s space. The native host decodes the pixels asynchronously. |
https://… / http://… | Loaded through the same transport as fetch, into a shared memory + disk cache with HTTP freshness (Cache-Control, Expires, ETag / Last-Modified revalidation). A second launch draws cached images without a request. |
data:image/… | Decoded from the URL; its size is known immediately. |
Formats: PNG, JPEG, WebP, GIF (the first frame) and SVG. Anything else, a missing file or a path
outside the project fails the build (image-format, image-missing, image-outside).
On a native React screen, render visible text, a painted foreground element, or inline <svg> while the image decodes. An image alone cannot satisfy the React first-frame check.
Network images on Android
Android loads network images with HttpURLConnection, the same transport as fetch, so the
system proxy, per-app VPN, the system trust store and the app's
Network Security Config
(certificate pinning, the cleartext policy) apply. Cleartext http:// is off by default: such an
image fails (onError) unless the app allows that host. For a local test server, allow it in a
debug-only config, as examples/android does for the emulator's 10.0.2.2:
<!-- app/src/debug/res/xml/network_security_config.xml -->
<network-security-config>
<domain-config cleartextTrafficPermitted="true">
<domain includeSubdomains="false">10.0.2.2</domain>
</domain-config>
</network-security-config>
<!-- app/src/debug/AndroidManifest.xml -->
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<application android:networkSecurityConfig="@xml/network_security_config" />
</manifest>Release builds keep HTTPS only. The BakeNative library declares the INTERNET permission.
Layout and paint
- Natural size,
width/heightattributes (and their ratio forheight: auto), CSS sizes withmin-*/max-*: CSS 2.1 replaced-element sizing, as Chrome. - Give network images
widthandheight(or anaspect-ratio): the box is reserved before the image arrives, so nothing moves when it loads. object-fit(fill,contain,cover,none,scale-down) andobject-position.border-radiusclips the image (inside border and padding).background-image: url()withbackground-size,background-positionandbackground-repeat(repeat,no-repeat,repeat-x,repeat-y): one layer.loading="lazy"loads the image once it is within 1250 px of the viewport.onLoad/onErrorfire on the<img>.decoding(async,auto,sync) is accepted.
Memory and scaling
- Downscaling. An image drawn smaller than its natural size is filtered as Chromium's Skia does it. On Windows that is the mip level and bilinear filtering (not WIC's cubic), so the pixels match Chromium's.
- Decoded images on Android are kept within a budget (192 MB). When the app's UI is hidden or
the system runs low on memory, the host gives them back (
onTrimMemory): all of them while the UI is hidden, down to a half or a quarter of the budget while the app runs low or critical (least recently drawn first, so what is on screen stays). The encoded bytes are kept, and an image is decoded again when it is drawn next.
Not yet: srcset / <picture>, several background layers, background-repeat: space / round,
image-set(), animated GIF / WebP (the first frame is drawn).