From 8aefd88b7437be8abe65a587a2ce034d5863de78 Mon Sep 17 00:00:00 2001 From: Jason Lee Date: Fri, 20 Dec 2024 18:13:27 +0800 Subject: [PATCH] virtual_list: Try to use second item to measure. --- crates/ui/src/virtual_list.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/crates/ui/src/virtual_list.rs b/crates/ui/src/virtual_list.rs index 6cdf27ce..983dab3a 100644 --- a/crates/ui/src/virtual_list.rs +++ b/crates/ui/src/virtual_list.rs @@ -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();