#yew #list #virtual #webasm #web

yew-virtualized

一个只渲染可滚动列表屏幕部分的yew组件

2个不稳定版本

0.2.0 2023年3月20日
0.1.0 2022年6月1日

#1047 in WebAssembly

MIT/Apache

21KB
413

yew-virtualized

一个渲染可滚动列表可见部分的VirtualList yew组件。

此组件使用ResizeObserver API以允许列表中动态大小的项目。

快速示例

# Cargo.toml
yew-virtualized = "0.1.0"
fn items(idx: usize) -> Html {
    html! { format!("Item #{idx}") }
}

#[function_component(App)]
fn app() -> Html {
    html! {
        <VirtualList
            // An approximate item height that will be used to guess
            // space usage before the first render of an item. Subsequent renders
            // use the exact item height
            height_prior={30}
            // How many items to render, in total.
            item_count={100}
            // Callback function to render individual items by index in 0..item_count
            items={VirtualList::item_gen(items)}
            // Additional classes to apply to the root node
            classes={"scrollbar"} />
    }
}

依赖项

~15MB
~274K SLoC