Skip to main content

Composer

Struct Composer 

Source
pub struct Composer { /* private fields */ }

Implementations§

Source§

impl Composer

Source

pub fn new( slots: Rc<SlotsHost>, applier: Rc<dyn ApplierHost>, runtime: RuntimeHandle, observer: SnapshotStateObserver, root: Option<NodeId>, ) -> Self

Source

pub fn register_virtual_node( &self, node_id: NodeId, node: Box<dyn Node>, ) -> Result<(), NodeError>

Registers a virtual node in the Applier.

This is used by SubcomposeLayoutNode to register virtual container nodes so that subsequent insert_child commands can find them and attach children. Without this, virtual nodes would only exist in SubcomposeLayoutNodeInner.virtual_nodes and applier.get_mut(virtual_node_id) would fail, breaking child attachment.

Source

pub fn node_has_no_parent(&self, node_id: NodeId) -> bool

Checks if a node has no parent (is a root node). Used by SubcomposeMeasureScope to filter subcompose results.

Source

pub fn get_node_children(&self, node_id: NodeId) -> SmallVec<[NodeId; 8]>

Gets the children of a node from the Applier.

This is used by SubcomposeLayoutNode to get children of virtual nodes directly from the Applier, where insert_child commands have been applied.

Source

pub fn nodes_need_measure(&self, node_ids: &[NodeId]) -> bool

Source

pub fn record_subcompose_child(&self, child_id: NodeId)

Records a child node in the current parent frame’s expected children list.

Used by SubcomposeLayout’s perform_subcompose to register virtual nodes with the outer composer’s parent frame. This ensures that the pop_parent call at the end of subcompose_slot generates a correct SyncChildren command that preserves (rather than removes) the virtual nodes.

Without this, pop_parent would generate SyncChildren { expected: [] }, which removes all virtual nodes and their subtrees from the applier.

Source

pub fn clear_node_children(&self, node_id: NodeId)

Clears all children of a node in the Applier.

This is used by SubcomposeLayoutNode when reusing a virtual node for different content. Without clearing, old children remain attached, causing duplicate/interleaved items in lazy lists after scrolling.

Source

pub fn install<R>(&self, f: impl FnOnce(&Composer) -> R) -> R

Source

pub fn with_group<R>(&self, key: Key, f: impl FnOnce(&Composer) -> R) -> R

Source

pub fn cranpose_with_reuse<R>( &self, key: Key, options: RecomposeOptions, f: impl FnOnce(&Composer) -> R, ) -> R

Source

pub fn with_key<K: Hash, R>(&self, key: &K, f: impl FnOnce(&Composer) -> R) -> R

Source

pub fn remember<T: 'static>(&self, init: impl FnOnce() -> T) -> Owned<T>

Source

pub fn use_value_slot<'pass, T: 'static>( &'pass self, init: impl FnOnce() -> T, ) -> ValueSlotHandle<'pass, T>

Source

pub fn with_slot_value<'pass, T: 'static, R>( &'pass self, handle: ValueSlotHandle<'pass, T>, f: impl FnOnce(&T) -> R, ) -> R

Source

pub fn with_slot_value_mut<'pass, T: 'static, R>( &'pass self, handle: ValueSlotHandle<'pass, T>, f: impl FnOnce(&mut T) -> R, ) -> R

Source

pub fn mutable_state_of<T: Clone + 'static>( &self, initial: T, ) -> MutableState<T>

Source

pub fn mutable_state_list_of<T, I>(&self, values: I) -> SnapshotStateList<T>
where T: Clone + 'static, I: IntoIterator<Item = T>,

Source

pub fn mutable_state_map_of<K, V, I>(&self, pairs: I) -> SnapshotStateMap<K, V>
where K: Clone + Eq + Hash + 'static, V: Clone + 'static, I: IntoIterator<Item = (K, V)>,

Source

pub fn read_composition_local<T: Clone + 'static>( &self, local: &CompositionLocal<T>, ) -> T

Source

pub fn read_static_composition_local<T: Clone + 'static>( &self, local: &StaticCompositionLocal<T>, ) -> T

Source

pub fn current_recranpose_scope(&self) -> Option<RecomposeScope>

Source

pub fn phase(&self) -> Phase

Source

pub fn enter_phase(&self, phase: Phase)

Source

pub fn subcompose_measurement<R>( &self, state: &mut SubcomposeState, slot_id: SlotId, content: impl FnOnce(&Composer) -> R, ) -> (R, Vec<NodeId>)

Source

pub fn subcompose_in<R>( &self, slots: &Rc<SlotsHost>, root: Option<NodeId>, f: impl FnOnce(&Composer) -> R, ) -> Result<R, NodeError>

Source

pub fn capture_composition_locals(&self) -> CapturedCompositionLocals

Captures the composition-local values in scope at the current point of composition, as an opaque snapshot that can later be replayed with Composer::subcompose_slot_with_locals.

A SubcomposeLayout captures this while it is being composed and replays it while subcomposing off the measure pass, so content that is subcomposed during layout observes the same composition locals as the SubcomposeLayout call site — matching Jetpack Compose, where a subcomposition inherits the composition locals of the layout that created it rather than whatever happens to be in scope during measure (which, after composition unwinds, no longer carries ancestor providers).

Source

pub fn subcompose_slot<R>( &self, slots: &Rc<SlotsHost>, root: Option<NodeId>, f: impl FnOnce(&Composer) -> R, ) -> Result<(R, Vec<RecomposeScope>), NodeError>

Subcomposes content using an isolated SlotsHost without resetting it. Unlike subcompose_in, this preserves existing slot state across calls, allowing efficient reuse during measurement passes. This is critical for lazy lists where items need stable slot positions.

Source

pub fn subcompose_slot_with_locals<R>( &self, slots: &Rc<SlotsHost>, root: Option<NodeId>, locals: Option<&CapturedCompositionLocals>, f: impl FnOnce(&Composer) -> R, ) -> Result<(R, Vec<RecomposeScope>), NodeError>

Like Composer::subcompose_slot, but seeds the subcomposition with a composition-local snapshot captured earlier (see Composer::capture_composition_locals). When locals is None the locals in scope right now are used, preserving the plain behavior.

Source

pub fn skip_current_group(&self)

Source

pub fn runtime_handle(&self) -> RuntimeHandle

Source

pub fn set_recranpose_callback<F>(&self, callback: F)
where F: FnMut(&Composer) + 'static,

Source

pub fn set_recranpose_fn(&self, callback: fn(&Composer))

Source

pub fn with_composition_locals<R>( &self, provided: Vec<ProvidedValue>, f: impl FnOnce(&Composer) -> R, ) -> R

Source§

impl Composer

Source

pub fn use_state<T: Clone + 'static>( &self, init: impl FnOnce() -> T, ) -> MutableState<T>

Source

pub fn emit_node<N: Node + 'static>(&self, init: impl FnOnce() -> N) -> NodeId

Source

pub fn emit_recyclable_node<N: Node + 'static>( &self, init: impl FnOnce() -> N, reset: impl FnOnce(&mut N), ) -> NodeId

Source

pub fn with_node_mut<N: Node + 'static, R>( &self, id: NodeId, f: impl FnOnce(&mut N) -> R, ) -> Result<R, NodeError>

Source

pub fn push_parent(&self, id: NodeId)

Source

pub fn pop_parent(&self)

Source

pub fn apply_pending_commands(&self) -> Result<(), NodeError>

Applies any pending applier commands and runtime updates.

This is useful during measure-time subcomposition to ensure newly created nodes are available for measurement before the full composition is committed.

Source

pub fn register_side_effect(&self, effect: impl FnOnce() + 'static)

Source

pub fn take_side_effects(&self) -> Vec<Box<dyn FnOnce()>>

Trait Implementations§

Source§

impl Clone for Composer

Source§

fn clone(&self) -> Composer

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.