pub struct Lazy { /* private fields */ }Expand description
A subtree that is not built until the first time it would be shown — lazy when:$cond { … } in .rsx.
This is the general form of what a NavHost does per route:
pay for a screen when the user first reaches it, not at startup. Use it for anything expensive behind a
condition the user may never satisfy — a settings panel, an inspector, a tab body, a chart that only some
accounts see.
It is deliberately not what a reactive if $cond does. That builds its branch whenever the condition
turns true and disposes it when it turns false, so a repeatedly toggled panel is rebuilt every time and
loses whatever state it held. This builds once, on the first true, and from then on only shows or
hides the same subtree — so scroll position, form entry and in-flight work survive being closed and
reopened. The cost is symmetric: a subtree shown once is held until the whole block is dropped.
Implementations§
Source§impl Lazy
impl Lazy
Sourcepub fn new(
container_style: LayoutStyle,
visible: impl Fn() -> bool + 'static,
build: impl FnOnce() -> Result<Vec<Box<dyn LayoutItem>>, LayoutError> + 'static,
) -> Result<Self, LayoutError>
pub fn new( container_style: LayoutStyle, visible: impl Fn() -> bool + 'static, build: impl FnOnce() -> Result<Vec<Box<dyn LayoutItem>>, LayoutError> + 'static, ) -> Result<Self, LayoutError>
visible is the reactive condition; build constructs the children the first time it holds, against
the live layout tree from inside the tracking effect — the same way a reactive list builds its items.