From 11387ce9a9c8ab27e07b98315309de8c3a55dd7a Mon Sep 17 00:00:00 2001 From: Jet Li Date: Sat, 14 May 2022 18:30:26 +0800 Subject: [PATCH] improve use_infinite_scroll (#15) --- crates/yew-hooks/src/hooks/use_infinite_scroll.rs | 4 ++-- examples/yew-app/src/routes/hooks/use_infinite_scroll.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/yew-hooks/src/hooks/use_infinite_scroll.rs b/crates/yew-hooks/src/hooks/use_infinite_scroll.rs index 4cf92bd..16d3b31 100644 --- a/crates/yew-hooks/src/hooks/use_infinite_scroll.rs +++ b/crates/yew-hooks/src/hooks/use_infinite_scroll.rs @@ -66,13 +66,13 @@ where move || { load_more.set(false); }, - 150, + 100, ) }; use_event(node, "scroll", move |e: Event| { let element: Element = e.target_unchecked_into(); - if element.scroll_height() - element.scroll_top() <= element.client_height() { + if element.scroll_height() - element.scroll_top() <= element.client_height() + 100 { load_more.set(true); debounce.run(); } diff --git a/examples/yew-app/src/routes/hooks/use_infinite_scroll.rs b/examples/yew-app/src/routes/hooks/use_infinite_scroll.rs index 043fe03..d9312f7 100644 --- a/examples/yew-app/src/routes/hooks/use_infinite_scroll.rs +++ b/examples/yew-app/src/routes/hooks/use_infinite_scroll.rs @@ -11,7 +11,7 @@ pub fn infinite_scroll() -> Html { let state = state.clone(); use_infinite_scroll(node.clone(), move || { let max = state.current().len() + 1; - let mut more = vec![max, max + 1, max + 2, max + 3, max + 4]; + let mut more = vec![max, max + 1, max + 2, max + 3, max + 4, max + 5, max + 6]; state.append(&mut more); }); }