Skip to main content

SwiftUiBuilder

Trait SwiftUiBuilder 

Source
pub trait SwiftUiBuilder: Sized {
    // Required methods
    fn params<M>(self, params: impl IntoReactive<String, M>) -> Self;
    fn state_key(self, key: impl Into<String>) -> Self;
}
Expand description

Builder methods of SwiftUi, reachable through a Decorated (docs/api-style.md “Typed builders and erasure”): generic modifiers and typed ones chain in any order.

Required Methods§

Source

fn params<M>(self, params: impl IntoReactive<String, M>) -> Self

The JSON params string: a constant, a Signal<String>, or a Fn() -> String. When it’s reactive the hosted view follows it live: each change re-invokes the provider’s body with the new JSON (@State inside the view survives, see the crate docs).

Source

fn state_key(self, key: impl Into<String>) -> Self

Keep the hosted view’s SwiftUI state across unmount/remount. Without a key, leaving the piece’s branch (a tab switch, a when() going false, a page navigation) disposes the hosting view and its @State with it; with one, the native half retains the hosting view under key and hands the same instance back on the next mount, so sliders, scroll positions, @State/@StateObject all survive, and the mount’s current params are re-applied.

The key pins one hosting view for the app’s lifetime, so use it for the handful of views that want persistence, not per-row content. At most one live instance per key: two mounted pieces sharing a key would fight over one native view.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl<DecoratedInner: SwiftUiBuilder + Piece> SwiftUiBuilder for Decorated<DecoratedInner>

Source§

fn params<M>(self, params: impl IntoReactive<String, M>) -> Self

Source§

fn state_key(self, key: impl Into<String>) -> Self

Implementors§