Skip to main content

native_component

Function native_component 

Source
pub fn native_component<C: NativeComponent>(
    kind: &'static str,
    component: C,
    props: C::Props,
) -> NativeComponentView<C>
Expand description

Mount the registered NativeComponent C as one native slot, driven by props.

kind must be the same string the component was registered under (register_component); a slot naming a kind nothing registered is reported dead by the runtime rather than rendering. component is the value the app constructs fresh every rebuild — the value NativeComponent::on_event runs against when a listener the component attached fires — and props is the typed create/update payload the runtime diffs with PartialEq before any FFI crossing.

ⓘ
register_component::<Gauge>("gauge");          // once, at app init
// …then, in a rebuild:
native_component("gauge", Gauge::new(), GaugeProps { value: 42 })
    .size(160.0, 48.0)
    .interactive()
    .on_event(move |event| {
        if event.is_click() {
            taps.set(taps.get_untracked() + 1);
        }
    })

The returned view is a View<Outer> for every outer app-state type, exactly like the built-in builders.