Skip to content

Commit

Permalink
virtual_list: Try to use second item to measure.
Browse files Browse the repository at this point in the history
  • Loading branch information
huacnlee committed Dec 20, 2024
1 parent 1a4ee34 commit 8aefd88
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion crates/ui/src/virtual_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,10 @@ impl VirtualList {
return Size::default();
}

let item_ix = 0;
// Avoid use first item to measure, because in most cases, this first item many complex.
// So we try to use the second item to measure, if there is no second item, use the first item.
let item_ix = if self.items_count > 1 { 1 } else { 0 };

let mut items = (self.render_items)(item_ix..item_ix + 1, Size::default(), cx);
let Some(mut item_to_measure) = items.pop() else {
return Size::default();
Expand Down

0 comments on commit 8aefd88

Please sign in to comment.