story: Add lazy load option to List story. (#1535)
This commit is contained in:
parent
89041f9ab8
commit
001107438f
1 changed files with 19 additions and 2 deletions
|
|
@ -163,6 +163,7 @@ struct CompanyListDelegate {
|
||||||
query: SharedString,
|
query: SharedString,
|
||||||
loading: bool,
|
loading: bool,
|
||||||
eof: bool,
|
eof: bool,
|
||||||
|
lazy_load: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CompanyListDelegate {
|
impl CompanyListDelegate {
|
||||||
|
|
@ -311,8 +312,10 @@ impl ListDelegate for CompanyListDelegate {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn load_more(&mut self, window: &mut Window, cx: &mut Context<ListState<Self>>) {
|
fn load_more(&mut self, window: &mut Window, cx: &mut Context<ListState<Self>>) {
|
||||||
// TODO: The load more here will broken the scroll position,
|
if !self.lazy_load {
|
||||||
// because the extends will creates some new industries to make some new sections.
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
cx.spawn_in(window, async move |view, window| {
|
cx.spawn_in(window, async move |view, window| {
|
||||||
// Simulate network request, delay 1s to load data.
|
// Simulate network request, delay 1s to load data.
|
||||||
Timer::after(Duration::from_secs(1)).await;
|
Timer::after(Duration::from_secs(1)).await;
|
||||||
|
|
@ -366,6 +369,7 @@ impl ListStory {
|
||||||
query: "".into(),
|
query: "".into(),
|
||||||
loading: false,
|
loading: false,
|
||||||
eof: false,
|
eof: false,
|
||||||
|
lazy_load: false,
|
||||||
};
|
};
|
||||||
delegate.extend_more(100);
|
delegate.extend_more(100);
|
||||||
|
|
||||||
|
|
@ -464,6 +468,8 @@ impl Focusable for ListStory {
|
||||||
|
|
||||||
impl Render for ListStory {
|
impl Render for ListStory {
|
||||||
fn render(&mut self, _: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
fn render(&mut self, _: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||||
|
let lazy_load = self.company_list.read(cx).delegate().lazy_load;
|
||||||
|
|
||||||
v_flex()
|
v_flex()
|
||||||
.track_focus(&self.focus_handle)
|
.track_focus(&self.focus_handle)
|
||||||
.on_action(cx.listener(Self::selected_company))
|
.on_action(cx.listener(Self::selected_company))
|
||||||
|
|
@ -566,6 +572,17 @@ impl Render for ListStory {
|
||||||
cx.notify();
|
cx.notify();
|
||||||
})
|
})
|
||||||
})),
|
})),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
Checkbox::new("lazy_load")
|
||||||
|
.label("Lazy Load")
|
||||||
|
.checked(lazy_load)
|
||||||
|
.on_click(cx.listener(|this, check: &bool, _, cx| {
|
||||||
|
this.company_list.update(cx, |this, cx| {
|
||||||
|
this.delegate_mut().lazy_load = *check;
|
||||||
|
cx.notify();
|
||||||
|
})
|
||||||
|
})),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.child(
|
.child(
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue