Plugin nodes
A plugin's live control as a part of a screen — a map in a card, a camera box in a form, a web page
under a header, a call's video tiles: a node among the screen's children, a box sized by its styles
like a UIImage, drawn by the platform's own view. The same control full screen, with buttons over
it, is the plugin's view — a destination, never a child (NativeView).
- put a map, a camera preview, a web page or a call's video inside a screen
- size, round and place a plugin's control like any element
- check that the device draws the control before building the screen around it
- change what the control shows and learn whether the change went through
- react to what the control reports
- follow a finger over the control
Platforms: iOS, Android and the web; in the web player, on desktop and in headless tests a plugin node is an empty box of its size — check the node's supported.
At a glance
// app.json: "plugins": { "map": "*", "camera": "*" }
const map = UIMapNode({ center: [37.62, 55.75], zoom: 12 }).style({ height: 180, borderRadius: 16 })
const viewfinder = UICameraNode().style({ height: 240, borderRadius: 16 })
UIScreen(
UIMapNode.supported ? map : UIText('No map on this device'),
UICameraNode.supported ? viewfinder : UIText('No camera on this device'),
UIButton(UIText('Flip')).onClick(() => {
viewfinder.setFacingMode(viewfinder.facingMode === 'back' ? 'front' : 'back')
.catch(e => toast(e.message)) // "unavailable": no such camera
}),
).style({ p: 16, pt: 'safe-top', gap: 12 }).open()Which control is a node
Each one is documented with its plugin; what this page says holds for all of them.
| node | shows | page |
|---|---|---|
UIMapNode |
a vector map | map-view.md |
UICameraNode |
the camera's live preview | camera-view.md |
UIWebViewNode |
a web page | browser.md |
UIRTCVideoNode |
one video track of a call | rtc.md |
UIGlassTabBarNode |
the system's tab bar | pager.md |
Size and place a plugin node: its styles
A plugin node is laid out like any element: give it a height, or flex: 1 in a column — it
measures nothing itself, so a node without a size is an empty line. borderRadius, a border and a
shadow are painted over the control; the map, the camera, the web page and the video clip to their
corners (overflow: 'hidden' is their default style).
const page = UIWebViewNode({ url: 'https://example.com/terms' })
.style({ flex: 1, borderRadius: 12, borderWidth: 1, borderColor: '#00000020' })
UIScreen(UIText('Terms'), page, UIButton(UIText('Accept')))
.style({ p: 16, pt: 'safe-top', gap: 12 }).open()- It has no children: buttons that belong to it are its neighbours in the layout, or sit over it
with
position: 'absolute'in the same parent. - It knows nothing of the safe area: keep it inside the screen's padding.
Check that the device draws the node: supported
UIMapNode.supported: boolean // static, on every node's factory; asked on every readsupported is false where the host draws no such node: the web player, desktop, headless tests,
an app whose app.json does not list the plugin. A node built there is an empty box of its size,
and the first one of its kind prints a warning — branch on supported and show something else.
const body = UIRTCVideoNode.supported
? UIRTCVideoNode().style({ flex: 1 })
: UIText('Video calls need the phone app')
UIScreen(body).style({ p: 16, pt: 'safe-top' }).open()Change what a node shows: props and calls
A node is changed in one of two ways, and each of its members is one or the other — its plugin's page says which.
map.center = [30.31, 59.94] // a live prop: written, shown with the next frame
map.zoom = 14
await viewfinder.setFacingMode('front') // a setting: a call that answers
viewfinder.facingMode // 'front' — follows a call that went through- A live prop is written like a field: the map's
centerandzoom, a web page'surl, a video'strack. The write cannot fail for the app; its getter answers what was written last, never what the control did since (a map the user dragged still reads thecenteryou wrote). - A setting is changed by a call that resolves once the control has it and rejects where it is
asked: the camera's
setFacingModeandsetFlashMode, a web page'ssetStops. Its property (facingMode,flashMode,stops) is read-only and changes only when the call resolves. - Any other call —
takePhoto(),flyTo(),goBack()— is a promise the host settles. It rejects when the node was destroyed, and on a host that does not draw the node.
const viewfinder = UICameraNode().style({ height: 240 })
const torch = UIButton(UIText('Torch')).onClick(async () => {
try { await viewfinder.setFlashMode(viewfinder.flashMode === 'torch' ? 'off' : 'torch') }
catch (e) { toast('This camera has no torch') } // "unavailable": nothing changed
})
UIScreen(viewfinder, torch).style({ p: 16, pt: 'safe-top', gap: 12 }).open()React to what the node reports: its on… events
Each event of a node has a chainable on… method; the payload is what the control sent.
const map = UIMapNode({ center: [37.62, 55.75], zoom: 12 }).style({ flex: 1 })
.onReady(() => toast('The map is ready'))
.onError(e => toast(e.message))
UIScreen(map).open()An event reaches a node that is on a screen; a node that was removed hears nothing until it is back.
Follow a finger over a plugin node: onTouchStart
node.onTouchStart(cb: (ev) => void): this
ev.clientX, ev.clientY // where the finger came down, logical px
ev.track({ onMove?, onEnd?, onCancel? }) // follow that fingeronTouchStart fires when a finger comes down on the node, before the control tells a tap from a
drag. The control keeps its own gestures — the map still pans, the page still scrolls: the track
watches the finger and takes nothing from the control.
const map = UIMapNode({ center: [37.62, 55.75], zoom: 12 }).style({ flex: 1 })
const hint = UIText('Drag the map')
map.onTouchStart(ev => {
hint.text = 'Moving…'
ev.track({ onEnd: () => { hint.text = 'Drag the map' } })
})
UIScreen(hint, map).style({ pt: 'safe-top' }).open()The same control full screen: the plugin's view
A control that fills the screen with its buttons over it is the plugin's view — MapView,
CameraView, WebView, RTCVideoView — pushed as a destination with Router.push(view) and its
controls in view.widgets(...) (NativeView). A view is never a child of a
screen, and a node has no open, onBack or widgets. Their calls and settings are the same.
A node of your own plugin
A control of your own native code that must sit in a layout is a host node of your own plugin: its
contract declares the props, the events and the calls, and lecodes plugin gen writes the element
the app builds (Write a native plugin, The plugin contract).
See also
- NativeView — the same controls full screen, as destinations
- Service — native code with no view
- Styling — the box styles a node takes