Skip to main content

LazyListScope

Trait LazyListScope 

Source
pub trait LazyListScope {
    // Required methods
    fn item_keyed<F>(
        &mut self,
        key: Option<u64>,
        content_type: Option<u64>,
        content: F,
    )
       where F: Fn() + 'static;
    fn items<I, F>(&mut self, items: I, item_content: F)
       where I: Into<LazyItems>,
             F: Fn(usize) + 'static;

    // Provided method
    fn item<F>(&mut self, content: F)
       where F: Fn() + 'static { ... }
}
Expand description

Receiver scope for lazy list content definition.

Used by LazyColumn and LazyRow to define list items. Matches Jetpack Compose’s LazyListScope.

§Example

lazy_column(modifier, state, |scope| {
    // Single item
    scope.item_keyed(Some(0), None, || {
        Text::new("Header")
    });

    // Multiple items
    scope.items(data.len(), Some(|i| data[i].id), None, |i| {
        Text::new(data[i].name.clone())
    });
});

Required Methods§

Source

fn item_keyed<F>( &mut self, key: Option<u64>, content_type: Option<u64>, content: F, )
where F: Fn() + 'static,

Adds one item with a stable identity and/or a reuse class.

key makes item state follow the item across reorders; content_type groups it with the rows it may be recycled into.

Source

fn items<I, F>(&mut self, items: I, item_content: F)
where I: Into<LazyItems>, F: Fn(usize) + 'static,

Adds a run of items.

A count is enough for the ordinary list — scope.items(20, |index| ...). Pass a LazyItems to name keys or reuse classes.

Provided Methods§

Source

fn item<F>(&mut self, content: F)
where F: Fn() + 'static,

Adds one item.

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§