LeCodesdocs

NativeView

A host-registered platform view — a map, QR scanner, camera preview, … The host registers a capability (registerView("map", factory) in its own code); when and with what to show it is app code. QRScanner and CameraView are typed wrappers over exactly this channel.

Host-optional — always guard with NativeView.isSupported(name) before offering the feature.

At a glance

TypeScript
if (NativeView.isSupported('map')) {
  const map = NativeView('map', { zoom: 12 })
    .style({ flexGrow: 1, borderRadius: 12 })
    .on('markerTap', data => toast(data.title))

  screen.append(map)                          // embedded in the layout…
  await map.call('setCenter', 37.62, 55.75)   // …and driven over the JSON channel
}

Destination AND element

Dual-natured like every Presentable:

  • Embedded: place it among a screen's children — it's laid out by its styles like any element (ElementStyle + drawable styles, animateTo/animateFrom, classes, onLayout).
  • Fullscreen: map.open({ transition }) / map.close() — or Router.push(map); it becomes the current destination with onOpen/onClose/onBackPressed like a screen.

One instance lives in one place at a time. Pushing an already-embedded instance fullscreen is promotion: the native view reparents with its state intact (a running camera keeps running). open() throws on hosts without the Presentable navigation channel.

The call/event channel

TypeScript
const result = await view.call(method, ...args)   // JSON-serialized both ways; rejects on
                                                  // unknown view/method or no host support
view.on(event, data => ...)                       // events the native side emits
view.off(event, callback)

params (the second factory argument) goes to the host factory at creation — use it for construct-time options; use call for everything after.

Writing a typed wrapper

Plugins ship a typed TS class over the raw channel rather than exposing strings to app code — see QRScanner/CameraView (src/plugins/) for the convention: pin the viewName/params, layer typed methods over call/on, and expose an isSupported getter.

For capabilities with no visual surface (GPS, bluetooth, …) use the service channel instead — the same protocol without a view; Geolocation is its first plugin.

See also