list: Fix the scroll_to_item not working (#1129)
This commit is contained in:
parent
e37369ea16
commit
37de698a61
2 changed files with 8 additions and 13 deletions
|
|
@ -523,14 +523,7 @@ impl Render for ListStory {
|
||||||
.small()
|
.small()
|
||||||
.on_click(cx.listener(|this, _, window, cx| {
|
.on_click(cx.listener(|this, _, window, cx| {
|
||||||
this.company_list.update(cx, |list, cx| {
|
this.company_list.update(cx, |list, cx| {
|
||||||
if let Some(selected) = list.selected_index() {
|
list.scroll_to_selected_item(window, cx);
|
||||||
list.scroll_to_item(
|
|
||||||
selected,
|
|
||||||
ScrollStrategy::Top,
|
|
||||||
window,
|
|
||||||
cx,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
})),
|
})),
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -202,7 +202,7 @@ where
|
||||||
pub fn scroll_to_item(
|
pub fn scroll_to_item(
|
||||||
&mut self,
|
&mut self,
|
||||||
ix: IndexPath,
|
ix: IndexPath,
|
||||||
_strategy: ScrollStrategy,
|
strategy: ScrollStrategy,
|
||||||
_: &mut Window,
|
_: &mut Window,
|
||||||
cx: &mut Context<Self>,
|
cx: &mut Context<Self>,
|
||||||
) {
|
) {
|
||||||
|
|
@ -215,7 +215,7 @@ where
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
self.deferred_scroll_to_index = Some(ix);
|
self.scroll_handle.scroll_to_item(ix.row, strategy);
|
||||||
cx.notify();
|
cx.notify();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -224,10 +224,12 @@ where
|
||||||
&self.scroll_handle
|
&self.scroll_handle
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn scroll_to_selected_item(&mut self, _window: &mut Window, cx: &mut Context<Self>) {
|
pub fn scroll_to_selected_item(&mut self, _: &mut Window, cx: &mut Context<Self>) {
|
||||||
if let Some(ix) = self.selected_index {
|
if let Some(ix) = self.selected_index {
|
||||||
self.deferred_scroll_to_index = Some(ix);
|
if let Some(ix) = self.rows_cache.position_of(&ix) {
|
||||||
cx.notify();
|
self.scroll_handle.scroll_to_item(ix, ScrollStrategy::Top);
|
||||||
|
cx.notify();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue