diff --git a/Cargo.toml b/Cargo.toml index 1e77af5..80cc532 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,7 +16,7 @@ homepage = "https://leptos-use.rs" leptos = "0.4" wasm-bindgen = "0.2" js-sys = "0.3" -default-struct-builder = "0.3" +default-struct-builder = "0.4" num = { version = "0.4", optional = true } serde = { version = "1", optional = true } serde_json = { version = "1", optional = true } diff --git a/examples/use_scroll/src/main.rs b/examples/use_scroll/src/main.rs index 23e7ac6..898e3a6 100644 --- a/examples/use_scroll/src/main.rs +++ b/examples/use_scroll/src/main.rs @@ -3,6 +3,8 @@ use leptos::*; use leptos_use::docs::{demo_or_body, BooleanDisplay}; use leptos_use::{use_scroll_with_options, ScrollBehavior, UseScrollOptions, UseScrollReturn}; +use web_sys::Event; + #[component] fn Demo(cx: Scope) -> impl IntoView { let el = create_node_ref::
(cx); @@ -24,7 +26,18 @@ fn Demo(cx: Scope) -> impl IntoView { arrived_state, directions, .. - } = use_scroll_with_options(cx, el, UseScrollOptions::default().behavior(behavior)); + } = use_scroll_with_options( + cx, + el, + UseScrollOptions::default() + .behavior(behavior) + .on_stop(move |_: Event| { + log!("scrolling stopped"); + }) + .on_scroll(move |_: Event| { + log!("scrolling"); + }), + ); view! { cx,
diff --git a/src/use_scroll.rs b/src/use_scroll.rs index e22bff1..3576218 100644 --- a/src/use_scroll.rs +++ b/src/use_scroll.rs @@ -1,6 +1,6 @@ use crate::core::ElementMaybeSignal; use crate::use_event_listener::use_event_listener_with_options; -use crate::utils::CloneableFnWithArg; +use crate::utils::CloneableFnMutWithArg; use crate::{use_debounce_fn_with_arg, use_throttle_fn_with_arg_and_options, ThrottleOptions}; use default_struct_builder::DefaultBuilder; use leptos::ev::EventDescriptor; @@ -456,12 +456,10 @@ pub struct UseScrollOptions { offset: ScrollOffset, /// Callback when scrolling is happening. - #[builder(into)] - on_scroll: Box>, + on_scroll: Box + 'static>, /// Callback when scrolling stops (after `idle` + `throttle` milliseconds have passed). - #[builder(into)] - on_stop: Box>, + on_stop: Box + 'static>, /// Options passed to the `addEventListener("scroll", ...)` call event_listener_options: web_sys::AddEventListenerOptions,