pub struct Dynamic(/* private fields */);Expand description
A dynamic view that can be updated.
Represents a view whose content can be changed dynamically at runtime.
You should avoid using this component if possible,
most of components in WaterUI already provide a way to update their content reactively.
Implementations§
Source§impl Dynamic
impl Dynamic
Sourcepub fn new() -> (DynamicHandler, Self)
pub fn new() -> (DynamicHandler, Self)
Creates a new Dynamic view along with its handler.
Returns a tuple of (handler, view) where the handler can be used to update the view’s content.
§Returns
A tuple containing the DynamicHandler and Dynamic view
Sourcepub fn watch<T, S, V: View>(value: S, f: impl 'static + Fn(T) -> V) -> impl Viewwhere
S: Signal<Output = T> + 'static,
T: 'static,
pub fn watch<T, S, V: View>(value: S, f: impl 'static + Fn(T) -> V) -> impl Viewwhere
S: Signal<Output = T> + 'static,
T: 'static,
Creates a Dynamic view that watches structural reactive state.
The provided function is used to convert the value to a view. Whenever the watched value changes, the entire child subtree is replaced. State owned by the replaced subtree is discarded. Prefer signal-aware component inputs, modifiers, metadata, and reactive collections for scalar values or collection membership. Use this only when the semantic view structure itself must change.
§Arguments
value- The reactive value to watchf- A function that converts the value to a view
§Returns
A Dynamic view that updates when the value changes
Sourcepub fn connect(self, receiver: impl Fn(Context<AnyView>) + 'static)
pub fn connect(self, receiver: impl Fn(Context<AnyView>) + 'static)
Connects the Dynamic view to a receiver function.
For internal use only.
The receiver function is called whenever the view content is updated. If there’s a temporary view stored (set before connecting), it will be immediately passed to the receiver.
§Arguments
receiver- A function that receives view updates
Sourcepub fn connect_with_pending_view(
self,
pending_view_slot: Rc<RefCell<Option<AnyView>>>,
receiver: impl Fn(Context<AnyView>) + 'static,
)
pub fn connect_with_pending_view( self, pending_view_slot: Rc<RefCell<Option<AnyView>>>, receiver: impl Fn(Context<AnyView>) + 'static, )
Connects the dynamic node while preserving a pending measurement view.
This is used by renderers that need to stage a temporary child view before the final backend receiver is attached.
Sourcepub fn with_unconnected_view<R>(
&self,
f: impl FnOnce(Option<&AnyView>) -> R,
) -> Option<R>
pub fn with_unconnected_view<R>( &self, f: impl FnOnce(Option<&AnyView>) -> R, ) -> Option<R>
Reads the current pre-connection view snapshot, if this dynamic node has not been connected yet.
Returns None when the node is already connected to a backend receiver.
Sourcepub fn with_unconnected_view_mut<R>(
&self,
f: impl FnOnce(&mut Option<AnyView>) -> R,
) -> Option<R>
pub fn with_unconnected_view_mut<R>( &self, f: impl FnOnce(&mut Option<AnyView>) -> R, ) -> Option<R>
Mutates the current pre-connection view snapshot before the dynamic node connects.
Returns None when the node is already connected to a backend receiver.
Sourcepub fn with_measurement_view_mut<R>(
&self,
f: impl FnOnce(&mut Option<AnyView>) -> R,
) -> Option<R>
pub fn with_measurement_view_mut<R>( &self, f: impl FnOnce(&mut Option<AnyView>) -> R, ) -> Option<R>
Mutates whichever view snapshot should be used for layout measurement.
Before connection this is the unconnected snapshot; after connection it targets the pending connected snapshot when one exists.